proof
stringlengths
279
439k
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma single_use: fixes r rs shows "\<bottom> \<star> ([r]@rs) = Some (snd r)" \nproof (induct rs) \ncase Nil \nthus ?case \nby simp \nnext \ncase (Cons r rs) \nthus ?case \nby auto \nqed \nlemma bot: "\<exists> rs . s = \<bottom> \<star> rs" \nproof (cases s) \ncase None \nhence "s = \<bottom> \<star> []" \nby auto \nthus ?thesis \nby blast \nnext \ncase (Some v) \nobtain r where "\<bottom> \<star> [r] = Some v" \nby force \nthus ?thesis \nusing Some \nby metis \nqed [/INST]\nusing assms single_use \nproof - \n{ \nassume 1:"s1 \<noteq> None" and 2:"s1 \<noteq> s2" \nobtain r rs where 3:"s1 = \<bottom> \<star> ([r]@rs)" \nusing bot \nusing 1 \nby (metis append_butlast_last_id pre_RDR.exec.simps(1)) \nobtain rs' where 4:"s2 = s1 \<star> rs'" \nusing assms \nby (auto simp add:less_eq_def) \nhave "s2 = \<bottom> \<star> ([r]@(rs@rs'))" \nusing 3 4 \nby (metis exec_append) \nhence "s1 = s2" \nusing 3 \nby (metis single_use) \nwith 2 \nhave False \nby auto \n} \nthus ?thesis \nby blast \nqed \ninterpretation RDR \<delta> \<gamma> \<bottom> \nproof (unfold_locales) \nfix s r \nassume "contains s r" \nshow "s \<bullet> r = s" \nproof - \nobtain rs where "s = \<bottom> \<star> rs" and "rs \<noteq> []" \nusing \<open>contains s r\<close> \nby (auto simp add:contains_def, force) \nthus ?thesis \nby (metis \<delta>.simps(2) rev_exhaust single_use) \nqed \nnext \nfix s and r r' :: "proc \<times> val" \nassume 1:"fst r \<noteq> fst r'" \nthus "\<gamma> s r = \<gamma> ((s \<bullet> r) \<bullet> r') r" \nby (metis \<delta>.simps \<gamma>.simps not_Some_eq) \nnext \nfix s1 s2 \nassume "s1 \<preceq> s2 \<and> s2 \<preceq> s1" \nthus "s1 = s2" \nby (metis prec_eq_None_or_equal) \nnext \nfix s1 s2 \nshow "\<exists> s . is_glb s s1 s2" \nby (simp add:is_glb_def is_lb_def) (metis bot pre_RDR.less_eq_def prec_eq_None_or_equal) \nnext \nfix s \nshow "\<bottom> \<preceq> s" \nby (metis bot pre_RDR.less_eq_def) \nnext \nfix s1 s2 s3 rs \nassume "s1 \<preceq> s2" and "s2 \<preceq> s3" and "s3 = s1 \<star> rs" \nthus "\<exists> rs' rs'' . s2 = s1 \<star> rs' \<and> s3 = s2 \<star> rs'' \<and> set rs' \<subseteq> set rs \<and> set rs'' \<subseteq> set rs" \nby (metis Consensus.prec_eq_None_or_equal in_set_insert insert_Nil list.distinct(1) pre_RDR.exec.simps(1) subsetI) \nqed \nend \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemmas ids = id1 id2 \ndefinition composition where "composition \<equiv> hide ((ioa 0 id1) \<parallel> (ioa id1 id2)) {act . \<exists>p c av . act = Switch id1 p c av }" \nlemmas comp_simps = hide_def composition_def ioa_def par2_def is_trans_def start_def actions_def asig_def trans_def \nlemmas trans_defs = Inv_def Lin_def Resp_def Init_def Abort_def Reco_def \ndeclare if_split_asm [split] \nsubsection \<open>A case rule for decomposing the transition relation of the composition of two SLins\<close> \ndeclare comp_simps [simp] \nlemma trans_elim: fixes s t a s' t' P assumes "(s,t) \<midarrow>a\<midarrow>composition\<longrightarrow> (s',t')" obtains (Invoke1) i p c where "Inv p c s s' \<and> t = t'" and "i < id1" and "a = Invoke i p c" | (Invoke2) i p c where "Inv p c t t' \<and> s = s'" and "id1 \<le> i \<and> i < id2" and "a = Invoke i p c" | (Switch1) p c av where "Abort p c av s s' \<and> Init p c av t t'" and "a = Switch id1 p c av" | (Switch2) p c av where "s = s' \<and> Abort p c av t t'" and "a = Switch id2 p c av" | (Response1) i p ou where "Resp p ou s s'\<and> t = t'" and "i < id1" and "a = Response i p ou" | (Response2) i p ou where "Resp p ou t t' \<and> s = s'" and "id1 \<le> i \<and> i < id2" and "a = Response i p ou" | (Lin1) "Lin s s' \<and> t = t'" and "a = Linearize 0" | (Lin2) "Lin t t' \<and> s = s'" and "a = Linearize id1" | (Reco2) "Reco t t' \<and> s = s'" and "a = Recover id1" \nproof %invisible (cases a) \ncase (Invoke i p c) \nwith assms \nhave "(Inv p c s s' \<and> t = t' \<and> i < id1) \<or> (Inv p c t t' \<and> s = s' \<and> id1 \<le> i \<and> i < id2)" \nby auto \nthus ?thesis \nusing Invoke that \nby blast \nnext \ncase (Response i p ou) \nwith assms \nhave "(Resp p ou s s' \<and> t = t' \<and> i < id1) \<or> (Resp p ou t t' \<and> s = s' \<and> id1 \<le> i \<and> i < id2)" \nby auto \nthus ?thesis \nusing Response that \nby metis \nnext \ncase (Switch i p c av) \nwith assms ids \nhave "(i = id1 \<and> Abort p c av s s'\<and> Init p c av t t') \<or> (i = id2 \<and> s = s' \<and> Abort p c av t t')" \nby auto \nthus ?thesis \nusing Switch that \nby metis \nnext \ncase (Linearize i) \nwith assms \nhave "(Lin s s' \<and> t = t' \<and> i = 0) \<or> (Lin t t' \<and> s = s' \<and> i = id1)" \nby auto \nthus ?thesis \nusing Linearize that \nby metis \nnext \ncase (Recover i) \nwith assms \nhave "Reco t t' \<and> s = s' \<and> a = Recover id1" \nby auto \nthus ?thesis \nusing Recover that \nby auto \nqed \ndeclare comp_simps [simp del] \nsubsection \<open>Definition of the Refinement Mapping\<close> \nfun f :: "(('a,'b,'c)SLin_state * ('a,'b,'c)SLin_state) \<Rightarrow> ('a,'b,'c)SLin_state" where "f (s1, s2) = \<lparr>pending = \<lambda> p. (if status s1 p \<noteq> Aborted then pending s1 p else pending s2 p), initVals = {}, abortVals = abortVals s2, status = \<lambda> p. (if status s1 p \<noteq> Aborted then status s1 p else status s2 p), dstate = (if dstate s2 = \<bottom> then dstate s1 else dstate s2), initialized = True\<rparr>" \nsubsection \<open>Invariants\<close> \ndeclare trans_defs [simp] \nfun P1 where "P1 (s1,s2) = (\<forall> p . status s1 p \<in> {Pending, Aborted} \<longrightarrow> fst (pending s1 p) = p)" \nfun P2 where "P2 (s1,s2) = (\<forall> p . status s2 p \<noteq> Sleep \<longrightarrow> fst (pending s2 p) = p)" \nfun P3 where "P3 (s1,s2) = (\<forall> p . (status s2 p = Ready \<longrightarrow> initialized s2))" \n(* Used to prove P19 only *) \nfun P4 where "P4 (s1,s2) = ((\<forall> p . status s2 p = Sleep) = (initVals s2 = {}))" \nfun P5 where "P5 (s1,s2) = (\<forall> p . status s1 p \<noteq> Sleep \<and> initialized s1 \<and> initVals s1 = {})" \nfun P6 where "P6 (s1,s2) = (\<forall> p . (status s1 p \<noteq> Aborted) = (status s2 p = Sleep))" \nfun P7 where "P7 (s1,s2) = (\<forall> c . status s1 c = Aborted \<and> \<not> initialized s2 \<longrightarrow> (pending s2 c = pending s1 c \<and> status s2 c \<in> {Pending, Aborted}))" \n(* Only used in the proof of P8a *) \nfun P8 where "P8 (s1,s2) = (\<forall> iv \<in> initVals s2 . \<exists> rs \<in> pendingSeqs s1 . iv = dstate s1 \<star> rs)" \nfun P8a where "P8a (s1,s2) = (\<forall> ivs \<in> initSets s2 . \<exists> rs \<in> pendingSeqs s1 . \<Sqinter>ivs = dstate s1 \<star> rs)" \nfun P9 where "P9 (s1,s2) = (initialized s2 \<longrightarrow> dstate s1 \<preceq> dstate s2)" \nfun P10 where "P10 (s1,s2) = ((\<not> initialized s2) \<longrightarrow> (dstate s2 = \<bottom>))" \nfun P11 where "P11 (s1,s2) = (initVals s2 = abortVals s1)" \nfun P12 where "P12 (s1,s2) = (initialized s2 \<longrightarrow> \<Sqinter> (initVals s2) \<preceq> dstate s2)" \nfun P13 where "P13 (s1,s2) = (finite (initVals s2) \<and> finite (abortVals s1) \<and> finite (abortVals s2))" \nfun P14 where "P14 (s1,s2) = (initialized s2 \<longrightarrow> initVals s2 \<noteq> {})" \nfun P15 where "P15 (s1,s2) = (\<forall> av \<in> abortVals s1 . dstate s1 \<preceq> av)" \nfun P16 where "P16 (s1,s2) = (dstate s2 \<noteq> \<bottom> \<longrightarrow> initialized s2)" \nfun P17 where \<comment> \<open>For the Response1 case of the refinement proof, in case a response is produced in the first instance and the second instance is already initialized\<close> "P17 (s1,s2) = (initialized s2 \<longrightarrow> (\<forall> p . ((status s1 p = Ready \<or> (status s1 p = Pending \<and> contains (dstate s1) (pending s1 p))) \<longrightarrow> (\<exists> rs . dstate s2 = dstate s1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p))) \<and> ((status s1 p = Pending \<and> \<not> contains (dstate s1) (pending s1 p)) \<longrightarrow> (\<exists> rs . dstate s2 = dstate s1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending s1 p)))))" \n(* Only used for proving P19 *) \nfun P18 where "P18 (s1,s2) = (abortVals s2 \<noteq> {} \<longrightarrow> (\<exists> p . status s2 p \<noteq> Sleep))" \nfun P19 where "P19 (s1,s2) = (abortVals s2 \<noteq> {} \<longrightarrow> abortVals s1 \<noteq> {})" \nfun P20 where "P20 (s1,s2) = (\<forall> av \<in> abortVals s2 . dstate s2 \<preceq> av)" \nfun P21 where "P21 (s1,s2) = (\<forall> av \<in> abortVals s2 . \<Sqinter>(abortVals s1) \<preceq> av)" \nfun P22 where "P22 (s1,s2) = (initialized s2 \<longrightarrow> dstate (f (s1,s2)) = dstate s2)" \nfun P23 where "P23 (s1,s2) = ((\<not> initialized s2) \<longrightarrow> pendingSeqs s1 \<subseteq> pendingSeqs (f (s1,s2)))" \nfun P25 where "P25 (s1,s2) = (\<forall> ivs . (ivs \<in> initSets s2 \<and> initialized s2 \<and> dstate s2 \<preceq> \<Sqinter>ivs) \<longrightarrow> (\<exists> rs' \<in> pendingSeqs (f (s1,s2)) . \<Sqinter>ivs = dstate s2 \<star> rs'))" \nfun P26 where "P26 (s1,s2) = (\<forall> p . (status s1 p = Aborted \<and> \<not> contains (dstate s2) (pending s1 p)) \<longrightarrow> (status s2 p \<in> {Pending,Aborted} \<and> pending s1 p = pending s2 p))" \nlemma P1_invariant: shows "invariant (composition) P1" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P1 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P1 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P1 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim) auto \nqed \nlemma P2_invariant: shows "invariant (composition) P2" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P2 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P2 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P2 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim) auto \nqed \nlemma P16_invariant: shows "invariant (composition) P16" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P16 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P16 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P16 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim) auto \nqed \nlemma P3_invariant: shows "invariant (composition) P3" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P3 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P3 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P3 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim) auto \nqed \nlemma P4_invariant: shows "invariant (composition) P4" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P4 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P4 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P4 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim) auto \nqed \nlemma P5_invariant: shows "invariant (composition) P5" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P5 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P5 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P5 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim) auto \nqed \nlemma P13_invariant: shows "invariant (composition) P13" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P13 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P13 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P13 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim, auto) \nqed \nlemma P20_invariant: shows "invariant (composition) P20" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P20 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P20 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" and reach: "reachable (composition) (s1,s2)" \nfrom reach \nhave P16:"P16 (s1,s2)" \nusing P16_invariant and ids \nby (metis IOA.invariant_def) \nshow "P20 (t1,t2)" \nusing trans and hyp and P16 \nby (cases rule:trans_elim, auto simp add:safeInits_def safeAborts_def initAborts_def uninitAborts_def bot) \nqed \nlemma P18_invariant: shows "invariant (composition) P18" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P18 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P18 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P18 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim, auto) \nqed \nlemma P14_invariant: shows "invariant (composition) P14" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P14 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P14 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P14 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim, auto simp add:safeInits_def) \nqed \nlemma P15_invariant: shows "invariant (composition) P15" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P15 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P15 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" and reach: "reachable (composition) (s1,s2)" \nfrom reach \nhave P5:"P5 (s1,s2)" \nusing P5_invariant and ids \nby (metis IOA.invariant_def) \nshow "P15 (t1,t2)" \nusing trans and hyp and P5 \nby (cases rule:trans_elim, auto simp add:less_eq_def safeAborts_def initAborts_def) \nqed \nlemma P6_invariant: shows "invariant (composition) P6" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P6 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P6 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P6 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim, force+) \nqed \nlemma P7_invariant: shows "invariant (composition) P7" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P7 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P7 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P7 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim) auto \nqed \nlemma P10_invariant: shows "invariant (composition) P10" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P10 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P10 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P10 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim) auto \nqed \nlemma P11_invariant: shows "invariant (composition) P11" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P11 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P11 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" \nshow "P11 (t1,t2)" \nusing trans and hyp \nby (cases rule:trans_elim, force+) \nqed \nlemma P8_invariant: shows "invariant (composition) P8" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P8 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P8 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" and reach: "reachable (composition) (s1,s2)" \nfrom reach \nhave P5:"P5 (s1,s2)" \nusing P5_invariant and ids \nby (metis IOA.invariant_def) \nfrom reach \nhave P1:"P1 (s1,s2)" \nusing P1_invariant and ids \nby (metis IOA.invariant_def) \nfrom reach \nhave P11:"P11 (s1,s2)" \nusing P11_invariant and ids \nby (metis IOA.invariant_def) \nshow "P8 (t1,t2)" \nusing trans and hyp \nproof (cases rule:trans_elim) \ncase (Invoke1 i p c) \nassume "P8 (s1,s2)" \nhave "pendingSeqs s1 \<subseteq> pendingSeqs t1" \nproof - \nhave "pending t1 = (pending s1)(p := (p,c))" and "status t1 = (status s1)(p := Pending)" and "status s1 p = Ready" \nusing Invoke1(1) \nby auto \nhence "pendingReqs s1 \<subseteq> pendingReqs t1" \nby (simp add:pendingReqs_def) force \nthus ?thesis \nby (auto simp add:pendingSeqs_def) \nqed \nmoreover \nhave "initVals t2 = initVals s2" and "dstate t1 = dstate s1" \nusing Invoke1(1) \nby auto \nultimately \nshow "P8 (t1,t2)" \nusing \<open>P8 (s1,s2)\<close> \nby fastforce \nnext \ncase Lin1 \nassume "P8 (s1,s2)" \nshow "P8 (t1,t2)" \nproof (simp, rule ballI) \nfix iv \nassume 0:"iv \<in> initVals t2" \nhave 1:"iv \<in> initVals s2" \nusing Lin1(1) 0 \nby simp \nhave 4:"iv \<in> abortVals s1" \nusing 1 P11 \nby simp \nobtain rs where 2:"rs \<in> pendingSeqs s1" and 3:"iv = dstate s1 \<star> rs" \nusing \<open>P8 (s1,s2)\<close> 1 \nby auto \nobtain rs' where 6:"dstate t1 = dstate s1 \<star> rs'" and 5:"dstate s1 \<star> rs' \<preceq> iv" \nusing Lin1(1) 1 4 \nby auto \nobtain rs'' where 7:"iv = (dstate s1 \<star> rs') \<star> rs''" and 8:"set rs'' \<subseteq> set rs" \nusing consistency 3 5 6 \nby simp (metis less_eq_def) \nhave 10:"rs'' \<in> pendingSeqs t1" \nproof - \nhave 9:"pendingSeqs t1 = pendingSeqs s1" \nusing Lin1(1) \nby (auto simp add:pendingSeqs_def pendingReqs_def) \nthus ?thesis \nusing 8 2 \nby (auto simp add:pendingSeqs_def) \nqed \nshow "\<exists> rs \<in> pendingSeqs t1 . iv = dstate t1 \<star> rs" \nusing 7 10 6 \nby auto \nqed \nnext \ncase (Response1 i p ou) \nassume ih:"P8 (s1,s2)" \nshow "P8 (t1,t2)" \nproof auto \nfix iv \nassume 1:"iv \<in> initVals t2" \nobtain rs where 2:"iv = dstate t1 \<star> rs" and 3:"rs \<in> pendingSeqs s1" \nusing 1 Response1(1) ih \nby auto \nhave 4:"pendingReqs t1 = ((pendingReqs s1) - {pending s1 p})" \nproof - \nhave "pending t1 = pending s1" and "status t1 = (status s1)(p := Ready)" and 5:"status s1 p = Pending" \nusing Response1(1) \nby auto \nmoreover \nhave "\<And> q . q \<noteq> p \<Longrightarrow> status s1 q \<in> {Pending,Aborted} \<Longrightarrow> pending s1 q \<noteq> pending s1 p" \nusing P1 5 \nby (metis P1.simps insertI1) \nultimately \nshow ?thesis \nby (simp add:pendingReqs_def) fastforce \nqed \nhave 8:"contains (dstate t1) (pending s1 p)" \nusing Response1(1) \nby simp \ndefine rs' where "rs' = filter (\<lambda> x . x \<noteq> (pending s1 p)) rs" \nhave 9:"rs' \<in> pendingSeqs t1" \nproof - \nhave 9:"pending s1 p \<notin> set rs'" \nby (auto simp add:rs'_def) \nhave 10:"rs' \<in> pendingSeqs s1" \nusing 3 \nby (auto simp add:rs'_def) (metis filter_is_subset mem_Collect_eq pendingSeqs_def subset_trans) \nshow ?thesis \nusing 10 9 4 \nby (auto simp add:pendingSeqs_def) \nqed \nhave 10:"iv = dstate t1 \<star> rs'" \nusing 8 2 idem_star rs'_def \nby fast \nshow "\<exists> rs \<in> pendingSeqs t1 . iv = dstate t1 \<star> rs" \nusing 10 9 \nby auto \nqed \nnext \ncase (Switch1 p c av) \nassume "P8 (s1,s2)" \nhave 1:"initialized s1 \<and> initVals s1 = {}" \nusing P5 \nby auto \nobtain av where 2:"initVals t2 = initVals s2 \<union> {av}" and 3:"av \<in> safeAborts s1" \nusing Switch1(1) \nby auto \nobtain rs where 4:"rs \<in> pendingSeqs s1" and 5:"av = dstate s1 \<star> rs" \nusing 1 3 \nby (auto simp add:safeAborts_def initAborts_def initSets_def) \nhave 6:"dstate s1 = dstate t1" \nusing Switch1(1) \nby simp \nhave 7:"pendingSeqs t1 = pendingSeqs s1" \nproof - \nhave "pendingReqs t1 = pendingReqs s1" \nusing Switch1(1) \nby (simp add:pendingReqs_def) fastforce \nthus ?thesis \nby (auto simp add:pendingSeqs_def) \nqed \nshow "P8 (t1,t2)" \nusing \<open>P8 (s1,s2)\<close> 2 4 5 6 7 \nby auto \nnext \ncase (Invoke2 i p c) \nassume "P8 (s1,s2)" \nthus "P8 (t1,t2)" \nusing Invoke2(1) \nby force \nnext \ncase Lin2 \nassume "P8 (s1,s2)" \nthus "P8 (t1,t2)" \nusing Lin2(1) \nby force \nnext \ncase (Response2 i p ou) \nassume "P8 (s1,s2)" \nthus "P8 (t1,t2)" \nusing Response2(1) \nby force \nnext \ncase (Switch2 p c av) \nassume "P8 (s1,s2)" \nthus "P8 (t1,t2)" \nusing Switch2(1) \nby force \nnext \ncase Reco2 \nassume "P8 (s1,s2)" \nthus "P8 (t1,t2)" \nusing Reco2(1) \nby force \nqed \nqed \nlemma P8a_invariant: shows "invariant (composition) P8a" \nproof (auto simp:invariant_def) \nfix s1 s2 ivs \nassume 1:"reachable (composition) (s1,s2)" and 2:"ivs \<in> initSets s2" \nhave 3:"finite ivs \<and> ivs \<noteq> {}" \nproof - \nhave "P13 (s1,s2)" \nusing P13_invariant 1 \nby (metis IOA.invariant_def) \nthus ?thesis \nusing 2 finite_subset \nby (auto simp add:initSets_def) \nqed \nhave 4:"\<forall> av \<in> ivs . \<exists> rs \<in> pendingSeqs s1 . av = dstate s1 \<star> rs" \nproof - \nhave P8:"P8 (s1,s2)" \nusing P8_invariant 1 \nby (metis IOA.invariant_def) \nthus ?thesis \nusing 2 \nby (auto simp add:initSets_def) \nqed \nshow "\<exists> rs \<in> pendingSeqs s1 . \<Sqinter>ivs = dstate s1 \<star> rs" \nusing 3 4 glb_common_set \nby (simp add:pendingSeqs_def, metis) \nqed \nlemma P12_invariant: shows "invariant (composition) P12" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P12 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P12 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" and reach: "reachable (composition) (s1,s2)" \nfrom reach \nhave P13:"P13 (s1,s2)" \nusing P13_invariant \nby (metis IOA.invariant_def) \nfrom reach \nhave P14:"P14 (s1,s2)" \nusing P14_invariant \nby (metis IOA.invariant_def) \nshow "P12 (t1,t2)" \nusing trans and hyp \nproof (cases rule:trans_elim) \ncase (Invoke1 i p c) \nassume "P12 (s1,s2)" \nthus "P12 (t1,t2)" \nusing Invoke1(1) \nby auto \nnext \ncase Lin1 \nassume "P12 (s1,s2)" \nthus "P12 (t1,t2)" \nusing Lin1(1) \nby auto \nnext \ncase (Response1 i p ou) \nassume "P12 (s1,s2)" \nthus "P12 (t1,t2)" \nusing Response1(1) \nby auto \nnext \ncase (Switch1 p c av) \nassume ih:"P12 (s1,s2)" \nhave "initialized s2 \<Longrightarrow> \<Sqinter> (initVals t2) \<preceq> \<Sqinter> (initVals s2)" \nproof - \nassume 1:"initialized s2" \nhave "initVals t2 = initVals s2 \<union> {av}" \nusing Switch1(1) \nby simp \nhence "\<Sqinter> (initVals t2) = \<Sqinter> (initVals s2) \<sqinter> av" \nusing insert_not_elem P13 P14 1 \nby (metis P13.simps P14.simps Un_empty_right Un_insert_right commute insert) \nthus ?thesis \nby (metis cobounded1) \nqed \nmoreover \nhave "dstate t2 = dstate s2" and "initialized s2 = initialized t2" \nusing Switch1(1) \nby auto \nultimately \nshow "P12 (t1,t2)" \nusing ih \nby auto (metis absorb2 coboundedI1) \nnext \ncase (Invoke2 i p c) \nassume "P12 (s1,s2)" \nthus "P12 (t1,t2)" \nusing Invoke2(1) \nby force \nnext \ncase Lin2 \nassume "P12 (s1,s2)" \nmoreover \nhave "initVals t2 = initVals s2" and "initialized s2" and "initialized t2" \nusing Lin2(1) \nby auto \nmoreover \nhave "dstate s2 \<preceq> dstate t2" \nusing Lin2(1) \nby auto (metis less_eq_def) \nultimately \nshow "P12 (t1,t2)" \nby auto (metis strict_iff_order strict_trans1) \nnext \ncase (Response2 i p ou) \nassume "P12 (s1,s2)" \nthus "P12 (t1,t2)" \nusing Response2(1) \nby force \nnext \ncase (Switch2 p c av) \nassume "P12 (s1,s2)" \nthus "P12 (t1,t2)" \nusing Switch2(1) \nby force \nnext \ncase Reco2 \nobtain d where 1:"d \<in> safeInits s2" and 2:"dstate t2 = d" \nusing Reco2(1) \nby force \nobtain ivs where 3:"ivs \<subseteq> initVals s2" and 4:"ivs \<noteq> {}" and 5:"\<Sqinter>ivs \<preceq> d" \nusing 1 \nby (auto simp add:safeInits_def initSets_def) (metis equals0D less_eq_def) \nhave 6:"\<Sqinter> (initVals s2) \<preceq> \<Sqinter> ivs" \nusing 3 P13 4 \nby (simp add: subset_imp) \nhave 7:"initVals s2 = initVals t2" \nusing Reco2(1) \nby auto \nshow "P12 (t1,t2)" \nusing 2 5 6 7 \nby (metis P12.simps absorb2 coboundedI1) \nqed \nqed \nlemma P19_invariant: shows "invariant (composition) P19" \nproof (auto simp only:invariant_def) \nfix s1 s2 \nassume 1:"reachable (composition) (s1,s2)" \nhave P4:"P4 (s1,s2)" \nusing P4_invariant 1 \nby (simp add:invariant_def) \nmoreover \nhave P18:"P18 (s1,s2)" \nusing P18_invariant 1 \nby (metis IOA.invariant_def) \nmoreover \nhave P11:"P11 (s1,s2)" \nusing P11_invariant 1 \nby (metis IOA.invariant_def) \nmoreover \nultimately \nshow "P19 (s1,s2)" \nby auto \nqed \nlemma P9_invariant: shows "invariant (composition) P9" \nproof (auto simp only:invariant_def) \nfix s1 s2 \nassume 1:"reachable (composition) (s1,s2)" \nhave P12:"P12 (s1,s2)" \nusing P12_invariant 1 \nby (simp add:invariant_def) \nhave P15:"P15 (s1,s2)" \nusing P15_invariant 1 \nby (metis IOA.invariant_def) \nhave P13:"P13 (s1,s2)" \nusing P13_invariant 1 \nby (metis IOA.invariant_def) \nhave P14:"P14 (s1,s2)" \nusing P14_invariant 1 \nby (metis IOA.invariant_def) \nhave P11:"P11 (s1,s2)" \nusing P11_invariant 1 \nby (metis IOA.invariant_def) \nhave "initialized s2 \<Longrightarrow> dstate s1 \<preceq> \<Sqinter>(abortVals s1)" \nusing P13 P15 P14 P11 boundedI \nby simp \nthus "P9 (s1,s2)" \nusing P12 P11 \nby simp (metis trans) \nqed \nlemma P17_invariant: shows "invariant (composition) P17" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P17 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P17 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" and reach:"reachable (composition) (s1,s2)" \nshow "P17 (t1,t2)" \nusing trans and hyp \nproof (cases rule:trans_elim) \ncase (Invoke1 i p c) \nassume "P17 (s1,s2)" \nthus "P17 (t1,t2)" \nusing Invoke1(1) \nby fastforce \nnext \ncase (Response1 i p ou) \nassume "P17 (s1,s2)" \nthus "P17 (t1,t2)" \nusing Response1(1) \nby auto \nnext \ncase (Switch1 p c av) \nassume "P17 (s1,s2)" \nthus "P17 (t1,t2)" \nusing Switch1(1) \nby auto \nnext \ncase (Invoke2 i p c) \nassume "P17 (s1,s2)" \nthus "P17 (t1,t2)" \nusing Invoke2(1) \nby force \nnext \ncase (Response2 i p ou) \nassume "P17 (s1,s2)" \nthus "P17 (t1,t2)" \nusing Response2(1) \nby force \nnext \ncase (Switch2 p c av) \nassume "P17 (s1,s2)" \nthus "P17 (t1,t2)" \nusing Switch2(1) \nby force \nnext \ncase Lin1 \nassume 1:"P17 (s1,s2)" \nobtain rs' where 2:"dstate t1 = dstate s1 \<star> rs'" \nusing Lin1(1) 1 \nby auto \nhave 3:"dstate s2 = dstate t2" \nusing Lin1(1) \nby auto \nhave 4:"initialized t2 \<Longrightarrow> dstate t1 \<preceq> dstate t2" \nproof - \nassume "initialized t2" \nmoreover \nhave "P9 (t1,t2)" \nusing reach trans P9_invariant \nby (metis IOA.invariant_def reachable_n) \nultimately \nshow ?thesis \nby auto \nqed \nshow "P17 (t1,t2)" \nproof(simp, auto) \nfix p \nassume 5:"initialized t2" and 6:"status t1 p = Ready" \nobtain rs where 7:"\<forall> r \<in> set rs . fst r \<noteq> p" and 8:"dstate t2 = dstate s1 \<star> rs" \nproof - \nobtain rs where "dstate s2 = dstate s1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nusing 1 5 6 Lin1(1) \nby force \nhence "\<forall> r \<in> set rs . fst r \<noteq> p" and "dstate t2 = dstate s1 \<star> rs" \nusing Lin1(1) \nby auto \nthus ?thesis \nusing that \nby blast \nqed \nhave 9:"dstate t1 \<preceq> dstate t2" \nusing 4 5 \nby auto \nobtain rs'' where 10:"dstate t2 = dstate t1 \<star> rs''" and 11:"set rs'' \<subseteq> set rs" \nusing consistency 2 8 9 \nby simp (metis less_eq_def) \nhave 12:"\<forall> r \<in> set rs'' . fst r \<noteq> p" \nusing 7 11 \nby blast \nthus "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nusing 10 12 \nby auto \nnext \nfix p \nassume 5:"initialized t2" and 6:"status t1 p = Pending" and 7:"\<not> contains (dstate t1) (pending t1 p)" \nobtain rs where 8:"\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending s1 p" and 9:"dstate t2 = dstate s1 \<star> rs" \nproof - \nhave 9:"\<not> contains (dstate s1) (pending s1 p)" \nusing 7 Lin1(1) contains_star \nby fastforce \nobtain rs where "dstate s2 = dstate s1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending s1 p)" \nusing 1 5 6 9 Lin1(1) \nby force \nhence "\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending s1 p" and "dstate t2 = dstate s1 \<star> rs" \nusing Lin1(1) \nby auto \nthus ?thesis \nusing that \nby blast \nqed \nhave 10:"dstate t1 \<preceq> dstate t2" \nusing 4 5 \nby auto \nobtain rs'' where 11:"dstate t2 = dstate t1 \<star> rs''" and 12:"set rs'' \<subseteq> set rs" \nusing consistency 2 9 10 \nby simp (metis less_eq_def) \nhave 13:"\<forall> r \<in> set rs'' . fst r = p \<longrightarrow> r = pending s1 p" \nusing 8 12 \nby blast \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending t1 p)" \nusing 11 13 Lin1(1) \nby auto \nnext \nfix p \nassume 5:"initialized t2" and 6:"status t1 p = Pending" and 7:"contains (dstate t1) (pending t1 p)" \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nproof (cases "contains (dstate s1) (pending s1 p)") \ncase True \nobtain rs where 8:"\<forall> r \<in> set rs . fst r \<noteq> p" and 9:"dstate t2 = dstate s1 \<star> rs" \nproof - \nobtain rs where "dstate s2 = dstate s1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nusing 1 5 6 True Lin1(1) \nby force \nhence "\<forall> r \<in> set rs . fst r \<noteq> p" and "dstate t2 = dstate s1 \<star> rs" \nusing Lin1(1) \nby auto \nthus ?thesis \nusing that \nby blast \nqed \nhave 10:"dstate t1 \<preceq> dstate t2" \nusing 4 5 \nby auto \nobtain rs'' where 11:"dstate t2 = dstate t1 \<star> rs''" and 12:"set rs'' \<subseteq> set rs" \nusing consistency 2 9 10 \nby simp (metis less_eq_def) \nhave 13:"\<forall> r \<in> set rs'' . fst r \<noteq> p" \nusing 8 12 \nby blast \nthus "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nusing 11 13 \nby auto \nnext \ncase False \nobtain rs'' where 8:"dstate t2 = dstate t1 \<star> rs''" and 9:"\<forall> r \<in> set rs'' . fst r = p \<longrightarrow> r = pending t1 p" \nproof - \nobtain rs where 8:"\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending s1 p" and 9:"dstate t2 = dstate s1 \<star> rs" \nproof - \nobtain rs where "dstate s2 = dstate s1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending s1 p)" \nusing 1 5 6 False Lin1(1) \nby force \nhence "\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending s1 p" and "dstate t2 = dstate s1 \<star> rs" \nusing Lin1(1) \nby auto \nthus ?thesis \nusing that \nby blast \nqed \nhave 10:"dstate t1 \<preceq> dstate t2" \nusing 4 5 \nby auto \nobtain rs'' where 11:"dstate t2 = dstate t1 \<star> rs''" and 12:"set rs'' \<subseteq> set rs" \nusing consistency 2 9 10 \nby simp (metis less_eq_def) \nhave 13:"\<forall> r \<in> set rs'' . fst r = p \<longrightarrow> r = pending s1 p" \nusing 8 12 \nby blast \nhave "dstate t2 = dstate t1 \<star> rs'' \<and> (\<forall> r \<in> set rs'' . fst r = p \<longrightarrow> r = pending t1 p)" \nusing 11 13 Lin1(1) \nby auto \nthus ?thesis \nusing that \nby blast \nqed \nhave 10:"dstate t1 \<star> rs'' = dstate t1 \<star> (filter (\<lambda> r . r \<noteq> pending t1 p) rs'')" \nusing 7 idem_star \nby blast \nhave 11:"\<forall> r \<in> set (filter (\<lambda> r . r \<noteq> pending t1 p) rs'') . fst r \<noteq> p" \nusing 9 \nby force \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nusing 8 10 11 \nby metis \nqed \nqed \nnext \ncase Lin2 \nassume 1:"P17 (s1,s2)" \n{ \nfix p \nassume 2:"status s1 p \<noteq> Aborted" \nhave "\<exists> rs' . dstate t2 = dstate s2 \<star> rs' \<and> (\<forall> r \<in> set rs' . fst r \<noteq> p)" \nproof - \nobtain rs' where 5:"dstate t2 = dstate s2 \<star> rs'" and 6:"rs' \<in> pendingSeqs s2" \nusing Lin2(1) \nby force \nhave 7:"\<forall> r \<in> set rs' . fst r \<noteq> p" \nproof (rule ballI) \nfix r \nassume "r \<in> set rs'" \nwith 6 \nhave "r \<in> pendingReqs s2" \nby (auto simp add:pendingSeqs_def) \nmoreover \nhave "P2 (s1,s2)" \nusing reach P2_invariant \nby (metis invariant_def) \nmoreover \nhave "status s2 p = Sleep" \nproof - \nhave "P6 (s1,s2)" \nusing reach P6_invariant \nby (metis invariant_def) \nthus ?thesis \nusing 2 Lin2(1) \nby force \nqed \nultimately \nshow "fst r \<noteq> p" \nby (auto simp add:pendingReqs_def) \nqed \nshow ?thesis \nusing 5 7 \nby force \nqed \n} \nnote a = this \nshow "P17 (t1,t2)" \nproof auto \nfix p \nassume 2:"initialized t2" and 3:"status t1 p = Ready" \nobtain rs where "dstate s2 = dstate s1 \<star> rs" and "\<forall> r \<in> set rs . fst r \<noteq> p" \nproof - \nhave "initialized s2" and "status s1 p = Ready" \nusing Lin2(1) 2 3 \nby auto \nthus ?thesis \nusing that 1 \nby fastforce \nqed \nmoreover \nobtain rs' where "dstate t2 = dstate s2 \<star> rs'" and "\<forall> r \<in> set rs' . fst r \<noteq> p" \nusing a 3 Lin2(1) \nby (metis SLin_status.distinct(11)) \nultimately \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nusing Lin2(1) \nby auto (metis UnE exec_append set_append) \nnext \nfix p \nassume 2:"initialized t2" and 3:"status t1 p = Pending" and 4:"contains (dstate t1) (pending t1 p)" \nobtain rs where "dstate s2 = dstate s1 \<star> rs" and "\<forall> r \<in> set rs . fst r \<noteq> p" \nproof - \nhave "initialized s2" and "status s1 p = Pending \<and> contains (dstate s1) (pending s1 p)" \nusing Lin2(1) 2 3 4 \nby auto \nthus ?thesis \nusing that 1 \nby fastforce \nqed \nmoreover \nobtain rs' where "dstate t2 = dstate s2 \<star> rs'" and "\<forall> r \<in> set rs' . fst r \<noteq> p" \nusing a 3 Lin2(1) \nby (metis SLin_status.distinct(9)) \nultimately \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nusing Lin2(1) \nby auto (metis UnE exec_append set_append) \nnext \nfix p \nassume 2:"initialized t2" and 3:"status t1 p = Pending" and 4:"\<not> contains (dstate t1) (pending t1 p)" \nobtain rs where "dstate s2 = dstate s1 \<star> rs" and "\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending s1 p" \nproof - \nhave "initialized s2" and "status s1 p = Pending \<and> \<not> contains (dstate s1) (pending s1 p)" \nusing Lin2(1) 2 3 4 \nby auto \nthus ?thesis \nusing that 1 \nby fastforce \nqed \nmoreover \nobtain rs' where "dstate t2 = dstate s2 \<star> rs'" and "\<forall> r \<in> set rs' . fst r \<noteq> p" \nusing a 3 Lin2(1) \nby (metis SLin_status.distinct(9)) \nultimately \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending t1 p)" \nusing Lin2(1) \nby auto (metis UnE exec_append set_append) \nqed \nnext \ncase Reco2 \nassume 0:"P17 (s1,s2)" \nobtain rs' where 1:"dstate t2 = dstate t1 \<star> rs'" and 2:"set rs' \<subseteq> pendingReqs s1 \<union> pendingReqs s2" \nproof - \nobtain ivs rs where 1:"ivs \<subseteq> initVals s2" and 2:"ivs \<noteq> {}" and 3:"dstate t2 = \<Sqinter>ivs \<star> rs" and 4:"rs \<in> pendingSeqs s2" \nusing Reco2(1) \nby (simp add:safeInits_def initSets_def, force) \nobtain rs'' where "set rs'' \<subseteq> pendingReqs s1" and "\<Sqinter>ivs = dstate s1 \<star> rs''" \nproof - \nhave "P8a (s1,s2)" \nusing reach P8a_invariant \nby (metis invariant_def) \nthus ?thesis \nusing that \nusing 1 2 \nby (auto simp add:initSets_def pendingSeqs_def) \nqed \nhence "dstate t2 = dstate t1 \<star> (rs''@rs) \<and> set rs'' \<subseteq> pendingReqs s1 \<and> set rs \<subseteq> pendingReqs s2" \nusing 3 4 Reco2(1) 4 \nby (metis exec_append mem_Collect_eq pendingSeqs_def) \nthus ?thesis \nusing that \nby force \nqed \n{ \nfix p r \nassume 1:"r \<in> pendingReqs s2" and 2:"status s1 p \<noteq> Aborted" \nhave "fst r \<noteq> p" \nproof - \nhave "P2 (s1,s2)" \nusing reach P2_invariant \nby (metis invariant_def) \nmoreover \nhave "P6 (s1,s2)" \nusing reach P6_invariant \nby (metis invariant_def) \nultimately \nshow ?thesis \nusing 1 2 Reco2(1) \nby (simp add:pendingReqs_def) (metis SLin_status.distinct(1,5)) \nqed \n} \nnote 3 = this \n{ \nfix r p \nassume 1:"r \<in> pendingReqs s1" and 2:"fst r = p" and 3:"status s1 p = Pending" \nhave "r = pending s1 p" \nproof - \nhave "P1 (s1,s2)" \nusing reach P1_invariant \nby (metis invariant_def) \nthus ?thesis \nusing 1 2 3 \nby (auto simp add:pendingReqs_def) \nqed \n} \nnote 10 = this \nshow "P17 (t1,t2)" \nproof (auto) \nfix p \nassume 4:"status t1 p = Ready" \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nproof - \n{ \nfix r \nassume 5:"r \<in> pendingReqs s1" \nhave "fst r \<noteq> p" \nproof - \nhave "P1 (s1,s2)" \nusing reach P1_invariant \nby (metis invariant_def) \nwith 4 5 Reco2(1) \nshow ?thesis \nby (auto simp add:pendingReqs_def) \nqed \n} \nmoreover \nhave "\<And> r . r \<in> pendingReqs s2 \<Longrightarrow> fst r \<noteq> p" \nusing 3 4 Reco2(1) \nby auto \nultimately \nshow ?thesis \nusing 1 2 \nby blast \nqed \nnext \nfix p \nassume 4:"status t1 p = Pending" and 5:"contains (dstate t1) (pending t1 p)" \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r \<noteq> p)" \nproof - \nlet ?rs = "filter (\<lambda> r . r \<noteq> pending t1 p) rs'" \nhave "dstate t2 = dstate t1 \<star> ?rs" \nusing 5 1 idem_star \nby metis \nmoreover \n{ \nfix r \nassume "r \<in> set ?rs" \nhave "fst r \<noteq> p" \nproof - \n{ \nfix r \nassume 6:"r \<in> set rs'" and 7:"fst r = p" \nhave "r = pending s1 p" \nproof - \nhave "\<And> r . r \<in> pendingReqs s2 \<Longrightarrow> fst r \<noteq> p" \nusing 3 4 Reco2(1) \nby auto \nmoreover \nhave "\<And> r . r \<in> pendingReqs s1 \<Longrightarrow> fst r = p \<Longrightarrow> r = pending s1 p" \nusing 10 4 Reco2(1) \nby auto \nultimately \nshow ?thesis \nusing 2 6 7 \nby (metis (lifting, no_types) UnE subsetD) \nqed \n} \nthus ?thesis \nusing \<open>r \<in> set ?rs\<close> Reco2(1) \nby fastforce \nqed \n} \nultimately \nshow ?thesis \nby blast \nqed \nnext \nfix p \nassume 4:"status t1 p = Pending" and 5:"\<not> contains (dstate t1) (pending t1 p)" \nshow "\<exists> rs . dstate t2 = dstate t1 \<star> rs \<and> (\<forall> r \<in> set rs . fst r = p \<longrightarrow> r = pending t1 p)" \nproof - \nhave "\<And> r . r \<in> pendingReqs s2 \<Longrightarrow> fst r \<noteq> p" \nusing 3 4 Reco2(1) \nby auto \nmoreover \nhave "\<And> r . r \<in> pendingReqs s1 \<Longrightarrow> fst r = p \<Longrightarrow> r = pending s1 p" \nusing 10 4 Reco2(1) \nby auto \nultimately \nshow ?thesis \nusing 1 2 Reco2(1) \nby (metis (lifting, no_types) UnE rev_subsetD) \nqed \nqed \nqed \nqed \nlemma P21_invariant: shows "invariant (composition) P21" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P21 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P21 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" and reach: "reachable (composition) (s1,s2)" \nshow "P21 (t1,t2)" \nproof (cases "initialized t2") \ncase True \nmoreover \nhave P12:"P12 (t1,t2)" \nusing P12_invariant reach trans \nby (metis invariant_def reachable_n) \nmoreover \nhave P11:"P11 (t1,t2)" \nusing P11_invariant reach trans \nby (metis IOA.invariant_def reachable_n) \nmoreover \nhave P20:"P20 (t1,t2)" \nusing P20_invariant reach trans \nby (metis IOA.invariant_def reachable_n) \nultimately \nshow "P21 (t1,t2)" \nby simp (metis pre_RDR.trans) \nnext \ncase False \nshow "P21 (t1,t2)" \nusing trans \nproof (cases rule:trans_elim) \ncase (Switch2 p c av) \nobtain av where "abortVals t2 = abortVals s2 \<union> {av}" and "\<Sqinter>(abortVals s1) \<preceq> av" \nproof - \nobtain ivs rs where 1:"abortVals t2 = abortVals s2 \<union> {\<Sqinter>ivs \<star> rs}" and 2:"ivs \<subseteq> initVals s2" and 3:"ivs \<noteq> {}" \nusing False Switch2(1) \nby (auto simp add:safeAborts_def uninitAborts_def initSets_def) \nhave 4:"\<Sqinter>(abortVals s1) \<preceq> \<Sqinter>ivs" \nproof - \nhave "P11 (s1,s2)" \nusing reach P11_invariant \nby (metis invariant_def) \nmoreover \nhave "P13 (s1,s2)" \nusing reach P13_invariant \nby (metis invariant_def) \nultimately \nshow ?thesis \nusing 2 3 \nby (simp add: subset_imp) \nqed \nshow ?thesis \nusing that 1 4 \nby simp (metis coboundedI2 less_eq_def orderE) \nqed \nwith hyp \nshow ?thesis \nusing Switch2(1) \nby simp \nnext \ncase (Switch1 p c av) \nshow ?thesis \nproof (cases "abortVals s1 = {}") \ncase False \nhave "\<Sqinter> (abortVals t1) \<preceq> \<Sqinter> (abortVals s1)" \nproof - \nobtain av where "abortVals t1 = abortVals s1 \<union> {av}" \nusing Switch1(1) \nby auto \nmoreover \nhave "P13 (s1,s2)" \nusing reach P13_invariant \nby (metis invariant_def) \nultimately \nshow ?thesis \nusing False \nby simp \nqed \nmoreover \nhave "abortVals t2 = abortVals s2" \nusing Switch1(1) \nby auto \nultimately \nshow ?thesis \nusing hyp \nby auto (metis coboundedI2 orderE) \nnext \ncase True \nhave "abortVals t2 = {}" \nproof - \nhave "P19 (s1,s2)" \nusing reach P19_invariant \nby (metis invariant_def) \nthus ?thesis \nusing True Switch1(1) \nby auto \nqed \nthus ?thesis \nby auto \nqed \nnext \ncase (Invoke1 p c) \nthus ?thesis \nusing hyp \nby simp \nnext \ncase (Invoke2 p c) \nthus ?thesis \nusing hyp \nby simp \nnext \ncase (Response1 p ou) \nthus ?thesis \nusing hyp \nby simp \nnext \ncase (Response2 p ou) \nthus ?thesis \nusing hyp \nby simp \nnext \ncase Lin1 \nthus ?thesis \nusing hyp \nby auto \nnext \ncase Lin2 \nthus ?thesis \nusing hyp \nby auto \nnext \ncase Reco2 \nthus ?thesis \nusing hyp \nby auto \nqed \nqed \nqed \nlemma P22_invariant: shows "invariant (composition) P22" \nproof (auto simp only:invariant_def) \nfix s1 s2 \nassume 1:"reachable (composition) (s1,s2)" \nhave P9:"P9 (s1,s2)" \nusing P9_invariant 1 \nby (simp add:invariant_def) \nshow "P22 (s1,s2)" \nproof (simp only:P22.simps, rule impI) \nassume "initialized s2" \nshow "dstate (f (s1,s2)) = dstate s2" \nproof (cases "dstate s2 = \<bottom>") \ncase False \nthus ?thesis \nby auto \nnext \ncase True \nshow "dstate (f (s1,s2)) = dstate s2" \nproof - \nhave "dstate s1 \<preceq> dstate s2" \nusing \<open>initialized s2\<close> and \<open>P9 (s1,s2)\<close> \nby auto \nhence "dstate s1 = dstate s2" \nusing True \nby (metis antisym bot) \nthus ?thesis \nby auto \nqed \nqed \nqed \nqed \nlemma P23_invariant: shows "invariant (composition) P23" \nproof (auto simp only:invariant_def) \nfix s1 s2 \nassume 1:"reachable (composition) (s1,s2)" \nshow "P23 (s1,s2)" \nproof (simp only:P23.simps, clarify) \nfix rs \nassume 2:"\<not>initialized s2" and 3:"rs\<in>pendingSeqs s1" \nshow "rs\<in> pendingSeqs (f (s1,s2))" \nproof - \n{ \nfix r \nassume 3:"r \<in> pendingReqs s1" \nhave 4:"status s1 (fst r) = Pending \<or> status s1 (fst r) = Aborted" and 5:"pending s1 (fst r) = r" \nproof - \nhave "P1 (s1,s2)" \nusing 1 P1_invariant \nby (metis invariant_def) \nthus "status s1 (fst r) = Pending \<or> status s1 (fst r) = Aborted" and "pending s1 (fst r) = r" \nusing 3 \nby (auto simp add:pendingReqs_def) \nqed \nhave "r \<in> pendingReqs (f (s1,s2))" \nusing 4 \nproof \nassume "status s1 (fst r) = Pending" \nwith 5 \nshow ?thesis \nby (auto simp add:pendingReqs_def) (metis SLin_status.distinct(9)) \nnext \nassume 6:"status s1 (fst r) = Aborted" \nhave 7:"pending s1 (fst r) = pending s2 (fst r) \<and> status s2 (fst r) \<in> {Pending,Aborted}" \nproof - \nhave "P7 (s1,s2)" \nusing 1 P7_invariant \nby (metis invariant_def) \nthus ?thesis \nusing 2 6 \nby auto \nqed \nshow ?thesis \nusing 6 5 7 \nby (simp add:pendingReqs_def, metis) \nqed \n} \nthus ?thesis \nusing 3 \nby (auto simp only:pendingSeqs_def) \nqed \nqed \nqed \nlemma P26_invariant: shows "invariant (composition) P26" \nproof (rule invariantI, simp_all only:split_paired_all) \nfix s1 s2 \nassume "(s1,s2) \<in> ioa.start (composition)" \nthus "P26 (s1,s2)" \nusing ids \nby (auto simp add:comp_simps) \nnext \nfix s1 s2 t1 t2 a \nassume hyp: "P26 (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>composition\<longrightarrow> (t1,t2)" and reach:"reachable composition (s1,s2)" \nshow "P26 (t1,t2)" \nusing trans and hyp \nproof (cases rule:trans_elim) \ncase Lin2 \nhence 1:"dstate s2 \<preceq> dstate t2" \nby auto (metis less_eq_def) \nhave 2:"t2 = s2\<lparr>dstate := dstate t2\<rparr>" and 3:"s1 = t1" \nusing Lin2(1) \nby auto \nshow ?thesis \nproof (simp, clarify) \nfix p \nassume 4:"status t1 p = Aborted" and 5:"\<not> contains (dstate t2) (pending t1 p)" \nhave 6:"status s1 p = Aborted" \nusing 3 4 \nby auto \nhave 7:"pending s1 p = pending t1 p" \nusing 3 \nby simp \nhave 8:"\<not> contains (dstate s2) (pending s1 p)" \nusing 1 5 7 \nby simp (metis contains_star less_eq_def) \nhave 11:"status s2 p \<in> {Pending,Aborted}" and 9:"pending s1 p = pending s2 p" \nusing hyp 6 8 \nby auto \nshow "(status t2 p = Pending \<or> status t2 p = Aborted) \<and> pending t1 p = pending t2 p" \nproof - \nfrom 2 \nhave "pending s2 = pending t2" and "status s2 = status t2" \nby ((cases s2, cases t2, auto)+) \nthus ?thesis \nusing 9 3 11 \nby auto \nqed \nqed \nnext \ncase Reco2 \nshow ?thesis \nproof (simp,clarify) \nfix p \nassume 1:"status t1 p = Aborted" \nhave 2:"status s1 p = Aborted" and 3:"\<not>initialized s2" \nusing 1 Reco2(1) \nby auto \nhave 4:"P7 (s1,s2)" \nusing reach P7_invariant \nby (metis invariant_def) \nhave 5:"status s2 p \<in> {Pending,Aborted}" and 6:"pending s1 p = pending s2 p" \nusing 3 4 2 \nby auto \nshow "(status t2 p = Pending \<or> status t2 p = Aborted) \<and> pending t1 p = pending t2 p" \nusing 5 6 Reco2(1) \nby auto \nqed \nnext \ncase Lin1 \nthus ?thesis \nusing hyp \nby force \nnext \ncase Response1 \nthus ?thesis \nusing hyp \nby force \nnext \ncase Response2 \nthus ?thesis \nusing hyp \nby force \nnext \ncase Invoke2 \nthus ?thesis \nusing hyp \nby force \nnext \ncase Switch1 \nthus ?thesis \nusing hyp \nby force \nnext \ncase Switch2 \nthus ?thesis \nusing hyp \nby force \nnext \ncase Invoke1 \nthus ?thesis \nusing hyp \nby force \nqed \nqed \nlemma P25_invariant: shows "invariant (composition) P25" \nproof (auto simp only:invariant_def) \nfix s1 s2 \nassume reach:"reachable (composition) (s1,s2)" \nshow "P25 (s1,s2)" \nproof (simp only:P25.simps, clarify) \nfix ivs \nassume 1:"ivs \<in> initSets s2" and 2:"initialized s2" and 3:"dstate s2 \<preceq> \<Sqinter>ivs" \nobtain rs' where 4:"dstate s2 \<star> rs' = \<Sqinter>ivs" and 5:"rs' \<in> pendingSeqs s1" and 6:"\<forall> r \<in> set rs' . \<not> contains (dstate s2) r" \nproof - \nhave 5:"dstate s1 \<preceq> dstate s2" \nproof - \nhave P9:"P9 (s1,s2)" \nusing P9_invariant reach \nby (simp add:invariant_def) \nthus ?thesis \nusing 2 \nby auto \nqed \nobtain rs where 6:"\<Sqinter>ivs = dstate s1 \<star> rs" and 7:"rs \<in> pendingSeqs s1" \nproof - \nhave P8a:"P8a (s1,s2)" \nusing P8a_invariant reach \nby (simp add:invariant_def) \nthus ?thesis \nusing that 1 \nby auto \nqed \nhave "\<exists> rs' . dstate s2 \<star> rs' = \<Sqinter> ivs \<and> rs' \<in> pendingSeqs s1" \nusing 3 5 6 7 consistency[of "dstate s1" "dstate s2" "\<Sqinter>ivs" rs] \nby (force simp add:pendingSeqs_def) \nwith this \nobtain rs' where "\<Sqinter>ivs = dstate s2 \<star> rs'" and "rs' \<in> pendingSeqs s1" \nby metis \nwith this \nshow ?thesis \nusing idem_star2 that \nby (metis mem_Collect_eq pendingSeqs_def subset_trans) \nqed \nhave 7:"rs' \<in> pendingSeqs (f (s1,s2))" \nproof - \n{ \nfix r \nassume "r \<in> set rs'" \nwith this \nobtain p where 8:"status s1 p = Pending \<or> status s1 p = Aborted" and 9:"r = pending s1 p" \nusing 5 \nby (auto simp add:pendingReqs_def pendingSeqs_def) \nfrom 8 \nhave "r \<in> pendingReqs (f (s1,s2))" \nproof \nassume "status s1 p = Pending" \nthus ?thesis \nusing 9 \nby (simp add:pendingReqs_def) (metis SLin_status.distinct(9)) \nnext \nassume 10:"status s1 p = Aborted" \nhence "status (f (s1,s2)) p = status s2 p" and "pending (f (s1,s2)) p = pending s2 p" \nby simp_all \nmoreover \nhave "status s2 p \<in> {Pending,Aborted} \<and> pending s2 p = pending s1 p" \nproof - \nhave "\<not> contains (dstate s2) r" \nusing 6 \<open>r \<in> set rs'\<close> \nby simp \nmoreover \nhave "P26 (s1,s2)" \nusing reach P26_invariant \nby (metis invariant_def) \nultimately \nshow ?thesis \nusing 10 9 \nby force \nqed \nultimately \nshow ?thesis \nusing 9 \nby (simp only:pendingReqs_def, force) \nqed \n} \nthus ?thesis \nby (auto simp add:pendingSeqs_def) \nqed \nshow "\<exists> rs \<in> pendingSeqs (f (s1,s2)) . \<Sqinter>ivs = dstate s2 \<star> rs" \nusing 4 7 \nby force \nqed \nqed \nsubsection \<open>Proof of the Idempotence Theorem\<close> \ndeclare %invisible hide_asig_def[simp] asig_comp2_def[simp] externals_def[simp] comp_simps[simp] [/INST]\nproof - \nhave same_input_sig:"inp (composition) = inp (ioa 0 id2)" \<comment> \<open>First we show that both automata have the same input and output signature\<close> \nusing ids \nby auto \nmoreover \nhave same_output_sig:"out (composition) = out (ioa 0 id2)" \<comment> \<open>Then we show that output signatures match\<close> \nusing ids \nby auto \nmoreover \nhave "traces (composition) \<subseteq> traces (ioa 0 id2)" \<comment> \<open>Finally we show trace inclusion\<close> \nproof - \nhave "ext (composition) = ext (ioa 0 id2)" \<comment> \<open>First we show that they have the same external signature\<close> \nusing same_input_sig and same_output_sig \nby simp \nmoreover \nhave "is_ref_map f (composition) (ioa 0 id2)" \<comment> \<open>Then we show that @{text f_comp} is a refinement mapping\<close> \nproof (auto simp only:is_ref_map_def) \nfix s1 s2 \nassume 1:"(s1,s2) \<in> ioa.start (composition)" \nshow "f (s1,s2) \<in> ioa.start (ioa 0 id2)" \nproof - \nhave 2:"ioa.start (ioa 0 id2) = start (0::nat)" \nby simp \nhave 3:"ioa.start (composition) = start (0::nat) \<times> start id1" \nby fastforce \nshow ?thesis \nusing 1 2 3 \nby simp \nqed \nnext \nfix s1 s2 t1 t2 :: "('a,'b,'c)SLin_state" and a :: "('a,'b,'c,'d)SLin_action" \nassume reach:"reachable (composition) (s1,s2)" and trans:"(s1,s2) \<midarrow>a\<midarrow>(composition)\<longrightarrow> (t1,t2)" \ndefine u where "u = f (s1,s2)" \ndefine u' where "u' = f (t1,t2)" \ntxt \<open>Lemmas and invariants\<close> \nhave "pendingReqs s2 \<subseteq> pendingReqs u" \nproof - \nhave "P6 (s1,s2)" \nusing reach P6_invariant \nby (metis invariant_def) \nthus ?thesis \nby (force simp add:pendingReqs_def u_def) \nqed \nnote lem1 = this \nhave "initialized u" \nby (auto simp add:u_def) \nhave "P1 (s1,s2)" and "P1 (t1,t2)" \nusing reach P1_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P6 (s1,s2)" and "P6 (t1,t2)" \nusing reach P6_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P7 (s1,s2)" and "P7 (t1,t2)" \nusing reach P7_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P8 (s1,s2)" and "P8 (t1,t2)" \nusing reach P8_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P9 (s1,s2)" and "P9 (t1,t2)" \nusing reach P9_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P10 (s1,s2)" and "P10 (t1,t2)" \nusing reach P10_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P13 (s1,s2)" and "P13 (t1,t2)" \nusing reach P13_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P15 (s1,s2)" and "P15 (t1,t2)" \nusing reach P15_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P16 (s1,s2)" and "P16 (t1,t2)" \nusing reach P16_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P17 (s1,s2)" and "P17 (t1,t2)" \nusing reach P17_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P19 (s1,s2)" and "P19 (t1,t2)" \nusing reach P19_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P21 (s1,s2)" and "P21 (t1,t2)" \nusing reach P21_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P22 (s1,s2)" and "P22 (t1,t2)" \nusing reach P22_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P25 (s1,s2)" and "P25 (t1,t2)" \nusing reach P25_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P8a (s1,s2)" and "P8a (t1,t2)" \nusing reach P8a_invariant trans invariant_def \nby (metis , metis reachable_n) \nhave "P23 (s1,s2)" and "P23 (t1,t2)" \nusing reach P23_invariant trans invariant_def \nby (metis , metis reachable_n) \nshow "\<exists> e . refines e (s1,s2) a (t1,t2) (ioa 0 id2) f" \nusing trans \nproof (cases rule:trans_elim) \ncase (Invoke1 i p c) \nlet ?e = "(u,[(a,u')])" \nhave 1:"is_exec_frag_of (ioa 0 id2) ?e" \nproof - \nhave 1:"status s1 p = Ready" and 2:"t2 = s2" and 3:"t1 = s1\<lparr>pending := (pending s1)(p := (p,c)), status := (status s1)(p := Pending)\<rparr>" \nusing Invoke1(1) \nby auto \nhave 4:"status u p = Ready" \nusing 1 u_def \nby auto \nhave 5:"u' = u\<lparr>pending := (pending u)(p := (p,c)), status := (status u)(p := Pending)\<rparr>" \nusing 2 3 u_def u'_def \nby auto \nhave 6:"Inv p c u u'" \nusing 4 5 \nby force \nshow ?thesis \nusing 6 Invoke1(3) ids \nby simp \nqed \nhave 2:"a \<in> ext (ioa 0 id2)" and 3:"trace (ioa.asig (ioa 0 id2)) ?e = [a]" \nusing Invoke1(2,3) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nshow ?thesis \nusing 1 2 3 \nby (simp only:refines_def u_def u'_def) (metis fst_conv last_state.simps(2) snd_conv) \nnext \ncase (Invoke2 i p c) \nlet ?e = "(u,[(a,u')])" \nhave 1:"is_exec_frag_of (ioa 0 id2) ?e" \nproof - \nhave 1:"status s2 p = Ready" and 2:"t1 = s1" and 3:"t2 = s2\<lparr>pending := (pending s2)(p := (p,c)), status := (status s2)(p := Pending)\<rparr>" \nusing Invoke2(1) \nby auto \nhave 4:"status u p = Ready" \nusing 1 u_def \<open>P6 (s1,s2)\<close> \nby auto \nhave 5:"u' = u\<lparr>pending := (pending u)(p := (p,c)), status := (status u)(p := Pending)\<rparr>" \nusing 2 3 u_def u'_def \<open>P6 (t1,t2)\<close> \nby fastforce \nhave 6:"Inv p c u u'" \nusing 4 5 \nby force \nshow ?thesis \nusing 6 Invoke2(3) ids \nby simp \nqed \nhave 2:"a \<in> ext (ioa 0 id2)" and 3:"trace (ioa.asig (ioa 0 id2)) ?e = [a]" \nusing Invoke2(2,3) \nby (auto simp add:trace_def schedule_def filter_act_def) \nshow ?thesis \nusing 1 2 3 \nby (simp only:refines_def u_def u'_def) (metis fst_conv last_state.simps(2) snd_conv) \nnext \ncase (Response2 i p ou) \nlet ?e = "(u,[(a,u')])" \nhave 1:"is_exec_frag_of (ioa 0 id2) ?e" \nproof - \nhave 1:"status s1 p = Aborted \<and> status t1 p = Aborted" \nproof - \nshow ?thesis \nusing \<open>P6 (s1,s2)\<close> \<open>P6 (t1,t2)\<close> Response2(1) \nby force \nqed \nhave 2:"status u p = Pending \<and> initialized u" \nusing 1 Response2(1) u_def \nby auto \nhave 3:"u' = u\<lparr>status := (status u)(p := Ready)\<rparr>" \nusing 1 Response2(1) u_def u'_def \nby (cases u, cases u', auto) \nhave 4:"ou = \<gamma> (dstate u) (pending u p) \<and> contains (dstate u) (pending u p)" \nproof (cases "dstate s2 = \<bottom>") \ncase False \nthus ?thesis \nusing 1 Response2(1) u_def \nby auto \nnext \ncase True \nhave "dstate s1 = dstate s2" \nproof - \nhave "dstate s1 \<preceq> dstate s2" \nusing Response2(1) \<open>P9 (s1,s2)\<close> \nby auto \nwith True \nshow ?thesis \nby (metis antisym bot) \nqed \nthus ?thesis \nusing 1 Response2(1) u_def \nby auto \nqed \nshow ?thesis \nusing 2 3 4 Response2(3) ids \nby auto \nqed \nhave 2:"a \<in> ext (ioa 0 id2)" and 3:"trace (ioa.asig (ioa 0 id2)) ?e = [a]" \nusing Response2(2,3) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nshow ?thesis \nusing 1 2 3 \nby (simp only:refines_def u_def u'_def) (metis fst_conv last_state.simps(2) snd_conv) \nnext \ncase (Response1 i p ou) \nlet ?e = "(u,[(a,u')])" \nhave 1:"is_exec_frag_of (ioa 0 id2) ?e" \nproof (cases "dstate s2 = \<bottom>") \ncase True \nhave 1:"status u p = Pending \<and> initialized u" \nusing Response1(1) u_def \nby auto \nhave 2:"u' = u\<lparr>status := (status u)(p := Ready)\<rparr>" \nusing Response1(1) u_def u'_def \nby (cases u, cases u', auto) \nhave 3:"ou = \<gamma> (dstate u) (pending u p) \<and> contains (dstate u) (pending u p)" \nusing Response1(1) True u_def \nby auto \nshow ?thesis \nusing 1 2 3 \<open>initialized u\<close> Response1(3) ids \nby auto \nnext \ncase False \nhave 1:"status u p = Pending \<and> initialized u" \nusing Response1(1) u_def \nby auto \nhave 2:"u' = u\<lparr>status := (status u)(p := Ready)\<rparr>" \nusing Response1(1) u_def u'_def \nby (cases u, cases u', auto) \nhave 3:"ou = \<gamma> (dstate u) (pending u p)" and 4:"contains (dstate u) (pending u p)" \nproof - \nhave 2:"contains (dstate s1) (pending s1 p)" \nusing Response1(1) \nby auto \nshow "contains (dstate u) (pending u p)" \nproof - \nhave 3:"dstate s1 \<preceq> dstate u" \nproof - \nhave "initialized s2" \nusing \<open>P16 (s1,s2)\<close> False \nby auto \nthus ?thesis \nusing \<open>P9 (s1,s2)\<close> u_def False refl \nby simp \nqed \nhave 4:"pending s1 p = pending u p" \nusing u_def Response1(1) \nby force \nshow ?thesis \nusing 2 3 4 \nby (metis contains_star less_eq_def) \nqed \nhave 4:"\<gamma> (dstate s1) (pending s1 p) = \<gamma> (dstate u) (pending u p)" \nproof - \nhave 4:"pending s1 p = pending u p" \nusing u_def Response1(1) \nby force \nobtain rs where 5:"dstate u = dstate s1 \<star> rs" and 6:"\<forall> r \<in> set rs . fst r \<noteq> p" \nproof - \nhave 7:"dstate u = dstate s2" \nusing u_def False \nby simp \nhave 6:"status s1 p = Pending \<and> contains (dstate s1) (pending s1 p)" \nusing Response1(1) \nby force \nhave 8:"initialized s2" \nusing False \<open>P16 (s1,s2)\<close> \nby auto \nshow ?thesis \nusing that \<open>P17 (s1,s2)\<close> 6 8 7 \nby fastforce \nqed \nhave 7:"fst (pending s1 p) = p" \nusing Response1(1) \<open>P1 (s1,s2)\<close> \nby auto \nshow ?thesis \nusing 4 5 6 7 2 idem2_star \nby auto \nqed \nthus "ou = \<gamma> (dstate u) (pending u p)" \nusing Response1(1) \nby simp \nqed \nthus ?thesis \nusing 1 2 3 Response1(3) ids \nby auto \nqed \nhave 2:"a \<in> ext (ioa 0 id2)" and 3:"trace (ioa.asig (ioa 0 id2)) ?e = [a]" \nusing Response1(2,3) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nshow ?thesis \nusing 1 2 3 \nby (simp only:refines_def u_def u'_def) (metis fst_conv last_state.simps(2) snd_conv) \nnext \ncase (Reco2) \nlet ?e = "(u,[(Linearize 0,u')])" \nhave "is_exec_frag_of (ioa 0 id2) ?e" \nproof - \nobtain rs where 1:"rs \<in> pendingSeqs u" and 2:"dstate u' = dstate u \<star> rs" and 3:"\<forall> av \<in> abortVals u . dstate u' \<preceq> av" \nproof - \nobtain rs where "set rs \<subseteq> pendingReqs s1 \<union> pendingReqs s2" and "dstate t2 = dstate s1 \<star> rs" and "\<forall> av \<in> abortVals s2 . dstate t2 \<preceq> av" \nproof - \nobtain ivs rs where 3:"ivs \<subseteq> initVals s2" and 4:"ivs \<noteq> {}" and 5:"dstate t2 = \<Sqinter>ivs \<star> rs" and 7:"rs \<in> pendingSeqs s2" and 6:"\<forall> av \<in> abortVals s2 . dstate t2 \<preceq> av" \nusing Reco2(1) \nby (auto simp add:safeInits_def initSets_def) (metis all_not_in_conv) \nobtain rs' where "\<Sqinter>ivs = dstate s1 \<star> rs'" and "set rs' \<subseteq> pendingReqs s1" \nproof - \n{ \nfix iv \nassume 7:"iv \<in> ivs" \nhave "\<exists> rs . set rs \<subseteq> pendingReqs s1 \<and> iv = dstate s1 \<star> rs" \nusing \<open>P8 (s1,s2)\<close> 7 3 \nby auto (metis mem_Collect_eq pendingSeqs_def rev_subsetD) \n} \nmoreover \nhave "finite ivs" \nusing \<open>P13 (s1,s2)\<close> 3 \nby (metis P13.simps rev_finite_subset) \nultimately \nshow ?thesis \nusing that glb_common_set 4 \nby metis \nqed \nhence "dstate t2 = dstate s1 \<star> (rs'@rs) \<and> set (rs'@rs) \<subseteq> pendingReqs s1 \<union> pendingReqs s2" \nusing 5 7 \nby (metis (lifting, no_types) Un_commute Un_mono exec_append mem_Collect_eq pendingSeqs_def set_append) \nthus ?thesis \nusing that 6 \nby blast \nqed \nmoreover \nhave "pendingReqs s1 \<union> pendingReqs s2 \<subseteq> pendingReqs u" \nproof - \nnote \<open>pendingReqs s2 \<subseteq> pendingReqs u\<close> \nmoreover \nhave "pendingReqs s1 \<subseteq> pendingReqs u" \nusing Reco2(1) \<open>P7 (s1,s2)\<close> \nby (auto simp add:pendingReqs_def u_def) \nultimately \nshow ?thesis \nby auto \nqed \nmoreover \nhave "abortVals u = abortVals s2" \nby (auto simp add:u_def) \nmoreover \nhave "dstate u = dstate s1" \nusing \<open>P16 (s1,s2)\<close> Reco2(1) u_def \nby force \nmoreover \nhave "dstate u' = dstate t2" \nusing Reco2(1) \<open>P22 (t1,t2)\<close> \nby (auto simp add:u'_def) \nultimately \nshow ?thesis \nusing that \nby (auto simp add:pendingSeqs_def, blast) \nqed \nmoreover \nhave "u' = u\<lparr>dstate := dstate u \<star> rs\<rparr>" \nusing 2 Reco2(1) u_def u'_def \nby force \nmoreover \nnote \<open>initialized u\<close> \nultimately \nshow ?thesis \nby auto \nqed \nmoreover \nhave "a \<notin> ext (ioa 0 id2)" and "trace (ioa.asig (ioa 0 id2)) ?e = []" \nusing Reco2(2) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nultimately \nshow ?thesis \nby (simp only:refines_def u_def u'_def) (metis fst_conv last_state.simps(2) snd_conv) \nnext \ncase (Switch1 p c av) \nlet ?e = "(u,[])" \nhave "is_exec_frag_of (ioa 0 id2) ?e" \nby auto \nmoreover \nhave "a \<notin> ext (ioa 0 id2)" and "trace (ioa.asig (ioa 0 id2)) ?e = []" \nusing Switch1(2) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nmoreover \nhave "u = u'" \nusing Switch1(1) u_def u'_def \nby auto \nultimately \nshow ?thesis \nusing refines_def[of ?e "(s1,s2)" a "(t1,t2)" "ioa 0 id2" f] u_def u'_def \nby (metis last_state.simps(1) fst_conv) \nnext \ncase Lin2 \nlet ?e = "(u,[(Linearize 0,u')])" \nhave "is_exec_frag_of (ioa 0 id2) ?e" \nproof - \nhave "u' = u\<lparr>dstate := dstate u'\<rparr>" \nusing Lin2(1) \nby (auto simp add:u_def u'_def) \nmoreover \nnote \<open>initialized u\<close> \nmoreover \nobtain rs where "dstate u' = dstate u \<star> rs" and "rs \<in> pendingSeqs u" and "\<forall> av \<in> abortVals u . dstate u' \<preceq> av" \nproof - \nobtain rs where 1:"dstate t2 = dstate s2 \<star> rs" and 2:"rs \<in> pendingSeqs s2" and 3:"\<forall> av \<in> abortVals s2 . dstate t2 \<preceq> av" \nusing Lin2(1) \nby force \nhave 4:"rs \<in> pendingSeqs u" \nusing 2 and \<open>pendingReqs s2 \<subseteq> pendingReqs u\<close> \nby (metis mem_Collect_eq pendingSeqs_def subset_trans) \nhave 5:"dstate u' = dstate u \<star> rs" and 6:"\<forall> av \<in> abortVals u . dstate u' \<preceq> av" \nproof - \nhave 7:"dstate u = dstate s2 \<and> dstate u' = dstate t2" \nusing \<open>P22 (s1,s2)\<close> and \<open>P22 (t1,t2)\<close> Lin2(1) \nby (auto simp add:u_def u'_def) \nshow "dstate u' = dstate u \<star> rs" \nusing 7 1 \nby auto \nshow "\<forall> av \<in> abortVals u . dstate u' \<preceq> av" \nproof - \nhave "abortVals s2 = abortVals u" \nby (auto simp add:u_def) \nthus ?thesis \nusing 7 3 \nby simp \nqed \nqed \nshow ?thesis \nusing that 4 5 6 \nby auto \nqed \nultimately \nshow ?thesis \nby auto \nqed \nmoreover \nhave "a \<notin> ext (ioa 0 id2)" and "trace (ioa.asig (ioa 0 id2)) ?e = []" \nusing Lin2(2) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nultimately \nshow ?thesis \nby (simp only:refines_def u_def u'_def) (metis fst_conv last_state.simps(2) snd_conv) \nnext \ncase Lin1 \nhave "u' = u\<lparr>dstate := dstate u'\<rparr>" \nusing Lin1(1) \nby (auto simp add:u_def u'_def) \nshow ?thesis \nproof (cases "initialized s2") \ncase False \nlet ?e = "(u,[(Linearize 0,u')])" \nhave "is_exec_frag_of (ioa 0 id2) ?e" \nproof - \nnote \<open>u' = u\<lparr>dstate := dstate u'\<rparr>\<close> \nmoreover \nnote \<open>initialized u\<close> \nmoreover \nobtain rs where "dstate u' = dstate u \<star> rs" and "rs \<in> pendingSeqs u" and "\<forall> av \<in> abortVals u . dstate u' \<preceq> av" \nproof - \nobtain rs where 1:"dstate t1 = dstate s1 \<star> rs" and 2:"rs \<in> pendingSeqs s1" and 3:"\<forall> av \<in> abortVals s1 . dstate t1 \<preceq> av" \nusing Lin1(1) \nby force \nhave 5:"pendingSeqs s1 \<subseteq> pendingSeqs u" \nusing False \<open>P7 (s1,s2)\<close> \nby (auto simp add:pendingReqs_def pendingSeqs_def u_def) \nhave 6:"dstate u = dstate s1 \<and> dstate u' = dstate t1" \nusing \<open>P16 (s1,s2)\<close> False Lin1(1) \nby (auto simp add:u_def u'_def) \nhave 4:"\<forall> av \<in> abortVals u . dstate u' \<preceq> av" \nproof (cases "abortVals u = {}") \ncase True \nthus ?thesis \nby auto \nnext \ncase False \nhave "dstate u' = dstate t1" \nusing 6 \nby auto \nmoreover \nhave "abortVals u = abortVals t2" \nusing Lin1(1) \nby (auto simp add:u_def) \nmoreover \nhave "dstate t1 \<preceq> \<Sqinter>(abortVals t1)" \nproof - \nhave "abortVals t1 = abortVals s1" \nusing Lin1(1) \nby auto \nmoreover \nhave "abortVals t1 \<noteq> {}" \nusing False \<open>P19 (t1,t2)\<close> Lin1(1) \nby (simp add: u_def) \nultimately \nshow ?thesis \nusing 3 \<open>P13 (t1,t2)\<close> \nby simp (metis boundedI) \nqed \nultimately \nshow ?thesis \nusing \<open>P21 (t1,t2)\<close> 3 \nby (metis P21.simps coboundedI2 orderE) \nqed \nshow ?thesis \nusing 1 2 3 4 5 6 that \nby auto \nqed \nultimately \nshow ?thesis \nby auto \nqed \nmoreover \nhave "a \<notin> ext (ioa 0 id2)" and "trace (ioa.asig (ioa 0 id2)) ?e = []" \nusing Lin1(2) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nultimately \nshow ?thesis \nby (simp only:refines_def u_def u'_def) (metis fst_conv last_state.simps(2) snd_conv) \nnext \ncase True \nlet ?e = "(u,[])" \nhave "is_exec_frag_of (ioa 0 id2) ?e" \nby auto \nmoreover \nhave "a \<notin> ext (ioa 0 id2)" and "trace (ioa.asig (ioa 0 id2)) ?e = []" \nusing Lin1(2) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nmoreover \nhave "last_state ?e = u'" \nproof - \nhave "dstate u = dstate s2 \<and> dstate u' = dstate t2" \nusing \<open>P22 (s1,s2)\<close> and \<open>P22 (t1,t2)\<close> and True and Lin1(1) \nby (auto simp add:u_def u'_def) \nthus ?thesis \nusing Lin1(1) \<open>u' = u\<lparr>dstate := dstate u'\<rparr>\<close> \nby simp \nqed \nultimately \nshow ?thesis \nusing refines_def[of ?e "(s1,s2)" a "(t1,t2)" "ioa 0 id2" f] \nby (simp only:u_def u'_def, auto) \nqed \nnext \ncase (Switch2 p c av) \nlet ?e = "(u,[(a,u')])" \nhave 1:"is_exec_frag_of (ioa 0 id2) ?e" \nproof - \nhave 1:"u' = u\<lparr>abortVals := (abortVals u) \<union> {av}, status := (status u)(p := Aborted)\<rparr>" and 2:"av \<in> safeAborts s2" and 3:"status u p = Pending" and 4:"pending u p = (p,c)" \nproof - \nhave 1:"t2 = s2\<lparr>abortVals := (abortVals s2) \<union> {av}, status := (status s2)(p := Aborted)\<rparr>" and 2:"av \<in> safeAborts s2" and 3:"s1 = t1" and 4:"status s2 p = Pending" \nusing Switch2(1) \nby auto \nshow 5:"status u p = Pending" \nusing \<open>P6 (s1,s2)\<close> 4 \nby (auto simp add:u_def) \nhave 6:"status u' p = Aborted" \nusing \<open>P6 (t1,t2)\<close> 1 \nby (auto simp add:u'_def) \nshow "pending u p = (p,c)" \nusing \<open>P6 (s1,s2)\<close> 4 Switch2(1) \nby (auto simp add:u_def) \nshow "u' = u\<lparr>abortVals := (abortVals u) \<union> {av}, status := (status u)(p := Aborted)\<rparr>" \nusing 1 3 5 6 \nby (auto simp add:u_def u'_def) \nshow "av \<in> safeAborts s2" \nusing 2 \nby assumption \nqed \nhave 5:"av \<in> safeAborts u" \nproof (cases "initialized s2") \ncase True \nhence 6:"dstate u = dstate s2" \nusing \<open>P22 (s1,s2)\<close> \nby (auto simp add:u_def) \nhave "(\<exists> rs \<in> pendingSeqs s2 . av = dstate s2 \<star> rs) \<or> (dstate s2 \<preceq> av \<and> (\<exists> ivs \<in> initSets s2 . dstate s2 \<preceq> \<Sqinter>ivs \<and> (\<exists> rs \<in> pendingSeqs s2 . av = \<Sqinter>ivs \<star> rs)))" \nproof - \nhave "av \<in> initAborts s2" \nusing 2 and True \nby (auto simp add:safeAborts_def) \nthus ?thesis \nby (auto simp add:initAborts_def) \nqed \nthus ?thesis \nproof \nassume "\<exists> rs \<in> pendingSeqs s2 . av = dstate s2 \<star> rs" \nmoreover \nnote \<open>initialized u\<close> \nultimately \nshow ?thesis \nusing \<open>pendingReqs s2 \<subseteq> pendingReqs u\<close> 6 \nby (simp add:safeAborts_def initAborts_def) (metis less_eq_def mem_Collect_eq pendingSeqs_def sup.coboundedI2 sup.orderE) \nnext \nassume 7:"dstate s2 \<preceq> av \<and> (\<exists> ivs \<in> initSets s2 . dstate s2 \<preceq> \<Sqinter>ivs \<and> (\<exists> rs \<in> pendingSeqs s2 . av = \<Sqinter>ivs \<star> rs))" \nshow ?thesis \nproof - \nhave 8:"dstate u \<preceq> av" \nusing 7 6 \nby auto \nobtain ivs rs' where 9:"ivs \<in> initSets s2" and 10:"dstate s2 \<preceq> \<Sqinter>ivs" and 11:"rs' \<in> pendingSeqs s2 \<and> av = \<Sqinter>ivs \<star> rs'" \nusing 7 \nby auto \nhave 12:"dstate u = dstate s2" \nusing True \<open>P22 (s1,s2)\<close> \nby (auto simp add:u_def) \nmoreover \nobtain rs where "rs \<in> pendingSeqs u" and "\<Sqinter>ivs = dstate s2 \<star> rs" \nusing \<open>P25 (s1,s2)\<close> True 9 10 \nby (auto simp add:u_def) \nultimately \nhave "av = dstate u \<star> (rs@rs')" and "rs@rs' \<in> pendingSeqs u" \nusing 11 \nby (simp_all add:pendingSeqs_def) (metis exec_append, metis lem1 subset_trans) \nthus ?thesis \nusing 8 \<open>initialized u\<close> \nby (auto simp add:safeAborts_def initAborts_def) \nqed \nqed \nnext \ncase False \nwith 2 \nhave 0:"av \<in> uninitAborts s2" \nby (auto simp add:safeAborts_def) \nshow ?thesis \nproof - \nobtain ivs rs where 1:"ivs \<in> initSets s2" and 2:"rs \<in>pendingSeqs s2" and 3:"av = \<Sqinter>ivs \<star> rs" \nusing 0 \nby (auto simp add:uninitAborts_def) \nhave 4:"rs \<in> pendingSeqs u" \nusing lem1 2 \nby (auto simp add:pendingSeqs_def) \nhave 5:"dstate u = dstate s1" \nusing False \<open>P10 (s1,s2)\<close> \nby (auto simp add:u_def) \nobtain rs' where 6:"\<Sqinter>ivs = dstate s1 \<star> rs'" and 7:"rs' \<in> pendingSeqs s1" \nusing 1 \<open>P8a (s1,s2)\<close> \nby auto \nhave 8:"rs' \<in> pendingSeqs u" \nusing False \<open>P23 (s1,s2)\<close> 7 \nby (auto simp add:u_def) \nhave 9:"av = dstate u \<star> (rs'@rs)" \nusing 3 5 6 \nby (metis exec_append) \nhave 10:"rs'@rs \<in> pendingSeqs u" \nusing 4 8 \nby (auto simp add:pendingSeqs_def) \nshow ?thesis \nusing 9 10 \<open>initialized u\<close> \nby (auto simp add:safeAborts_def initAborts_def less_eq_def) \nqed \nqed \nshow ?thesis \nusing 1 3 4 5 Switch2(2) \nby auto \nqed \nmoreover \nhave "a \<in> ext (ioa 0 id2)" and "trace (ioa.asig (ioa 0 id2)) ?e = [a]" \nusing Switch2(2) ids \nby (auto simp add:trace_def schedule_def filter_act_def) \nultimately \nshow ?thesis \nby (simp only:refines_def u_def u'_def) (metis fst_conv last_state.simps(2) snd_conv) \nqed \nqed \nultimately \nshow ?thesis \nusing ref_map_soundness \nby blast \nqed \nultimately \nshow ?thesis \nby (metis ioa_implements_def) \nqed \nend \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma internal_inter_external: assumes "is_asig sig" shows "internals sig \<inter> externals sig = {}" \nusing assms \nby (auto simp add:internals_def externals_def is_asig_def) \ndefinition hide_asig where "hide_asig asig actns \<equiv> \<lparr>inputs = inputs asig - actns, outputs = outputs asig - actns, internals = internals asig \<union>actns\<rparr>" \nend \nsubsection \<open>I/O Automata\<close> \ntype_synonym ('s,'a) transition = "'s \<times> 'a \<times> 's" \nrecord ('s,'a) ioa = asig::"'a signature" start::"'s set" trans::"('s,'a)transition set" \ncontext IOA begin \nabbreviation "act A \<equiv> actions (asig A)" \nabbreviation "ext A \<equiv> externals (asig A)" \nabbreviation int where "int A \<equiv> internals (asig A)" \nabbreviation "inp A \<equiv> inputs (asig A)" \nabbreviation "out A \<equiv> outputs (asig A)" \nabbreviation "local A \<equiv> locals (asig A)" \ndefinition is_ioa::"('s,'a) ioa \<Rightarrow> bool" where "is_ioa A \<equiv> is_asig (asig A) \<and> (\<forall> triple \<in> trans A . (fst o snd) triple \<in> act A)" \ndefinition hide where "hide A actns \<equiv> A\<lparr>asig := hide_asig (asig A) actns\<rparr>" \ndefinition is_trans::"'s \<Rightarrow> 'a \<Rightarrow> ('s,'a)ioa \<Rightarrow> 's \<Rightarrow> bool" where "is_trans s1 a A s2 \<equiv> (s1,a,s2) \<in> trans A" \nnotation is_trans ("_ \<midarrow>_\<midarrow>_\<longrightarrow> _" [81,81,81,81] 100) \ndefinition rename_set where "rename_set A ren \<equiv> {b. \<exists> x \<in> A . ren b = Some x}" \ndefinition rename where "rename A ren \<equiv> \<lparr>asig = \<lparr>inputs = rename_set (inp A) ren, outputs = rename_set (out A) ren, internals = rename_set (int A) ren\<rparr>, start = start A, trans = {tr. \<exists> x . ren (fst (snd tr)) = Some x \<and> (fst tr) \<midarrow>x\<midarrow>A\<longrightarrow> (snd (snd tr))}\<rparr>" \ntext \<open>Reachable states and invariants\<close> \ninductive reachable :: "('s,'a) ioa \<Rightarrow> 's \<Rightarrow> bool" for A :: "('s,'a) ioa" where reachable_0: "s \<in> start A \<Longrightarrow> reachable A s" | reachable_n: "\<lbrakk> reachable A s; s \<midarrow>a\<midarrow>A\<longrightarrow> t \<rbrakk> \<Longrightarrow> reachable A t" \ndefinition invariant where "invariant A P \<equiv> (\<forall> s . reachable A s \<longrightarrow> P(s))" \ntheorem invariantI: fixes A P assumes "\<And> s . s \<in> start A \<Longrightarrow> P s" and "\<And> s t a . \<lbrakk>reachable A s; P s; s \<midarrow>a\<midarrow>A\<longrightarrow> t\<rbrakk> \<Longrightarrow> P t" shows "invariant A P" \nproof - \n{ \nfix s \nassume "reachable A s" \nhence "P s" \nproof (induct rule:reachable.induct) \nfix s \nassume "s \<in> start A" \nthus "P s" \nusing assms(1) \nby simp \nnext \nfix a s t \nassume "reachable A s" and "P s" and " s \<midarrow>a\<midarrow>A\<longrightarrow> t" \nthus "P t" \nusing assms(2) \nby simp \nqed \n} \nthus ?thesis \nby (simp add:invariant_def) \nqed \nend \nsubsection \<open>Composition of Families of I/O Automata\<close> \nrecord ('id, 'a) family = ids :: "'id set" memb :: "'id \<Rightarrow> 'a" \ncontext IOA begin \ndefinition is_ioa_fam where "is_ioa_fam fam \<equiv> \<forall> i \<in> ids fam . is_ioa (memb fam i)" \ndefinition compatible2 where "compatible2 A B \<equiv> out A \<inter> out B = {} \<and> int A \<inter> act B = {} \<and> int B \<inter> act A = {}" \ndefinition compatible::"('id, ('s,'a)ioa) family \<Rightarrow> bool" where "compatible fam \<equiv> finite (ids fam) \<and> (\<forall> i \<in> ids fam . \<forall> j \<in> ids fam . i \<noteq> j \<longrightarrow> compatible2 (memb fam i) (memb fam j))" \ndefinition asig_comp2 where "asig_comp2 A B \<equiv> \<lparr>inputs = (inputs A \<union> inputs B) - (outputs A \<union> outputs B), outputs = outputs A \<union> outputs B, internals = internals A \<union> internals B\<rparr>" \ndefinition asig_comp::"('id, ('s,'a)ioa) family \<Rightarrow> 'a signature" where "asig_comp fam \<equiv> \<lparr> inputs = \<Union>i\<in>(ids fam). inp (memb fam i) - (\<Union>i\<in>(ids fam). out (memb fam i)), outputs = \<Union>i\<in>(ids fam). out (memb fam i), internals = \<Union>i\<in>(ids fam). int (memb fam i) \<rparr>" \ndefinition par2 (infixr "\<parallel>" 10) where "A \<parallel> B \<equiv> \<lparr>asig = asig_comp2 (asig A) (asig B), start = {pr. fst pr \<in> start A \<and> snd pr \<in> start B}, trans = {tr. let s = fst tr; a = fst (snd tr); t = snd (snd tr) in (a \<in> act A \<or> a \<in> act B) \<and> (if a \<in> act A then fst s \<midarrow>a\<midarrow>A\<longrightarrow> fst t else fst s = fst t) \<and> (if a \<in> act B then snd s \<midarrow>a\<midarrow>B\<longrightarrow> snd t else snd s = snd t) }\<rparr>" \ndefinition par::"('id, ('s,'a)ioa) family \<Rightarrow> ('id \<Rightarrow> 's,'a)ioa" where "par fam \<equiv> let ids = ids fam; memb = memb fam in \<lparr> asig = asig_comp fam, start = {s . \<forall> i\<in>ids . s i \<in> start (memb i)}, trans = { (s, a, s') . (\<exists> i\<in>ids . a \<in> act (memb i)) \<and> (\<forall> i\<in>ids . if a \<in> act (memb i) then s i \<midarrow>a\<midarrow>(memb i)\<longrightarrow> s' i else s i = (s' i)) } \<rparr>" \nlemmas asig_simps = hide_asig_def is_asig_def locals_def externals_def actions_def hide_def compatible_def asig_comp_def \nlemmas ioa_simps = rename_def rename_set_def is_trans_def is_ioa_def par_def \nend \nsubsection \<open>Executions and Traces\<close> \ntype_synonym ('s,'a)pairs = "('a\<times>'s) list" \ntype_synonym ('s,'a)execution = "'s \<times> ('s,'a)pairs" \ntype_synonym 'a trace = "'a list" \nrecord ('s,'a)execution_module = execs::"('s,'a)execution set" asig::"'a signature" \nrecord 'a trace_module = traces::"'a trace set" asig::"'a signature" \ncontext IOA begin \nfun is_exec_frag_of::"('s,'a)ioa \<Rightarrow> ('s,'a)execution \<Rightarrow> bool" where "is_exec_frag_of A (s,(ps#p')#p) = (snd p' \<midarrow>fst p\<midarrow>A\<longrightarrow> snd p \<and> is_exec_frag_of A (s, (ps#p')))" | "is_exec_frag_of A (s, [p]) = s \<midarrow>fst p\<midarrow>A\<longrightarrow> snd p" | "is_exec_frag_of A (s, []) = True" \ndefinition is_exec_of::"('s,'a)ioa \<Rightarrow> ('s,'a)execution \<Rightarrow> bool" where "is_exec_of A e \<equiv> fst e \<in> start A \<and> is_exec_frag_of A e" \ndefinition filter_act where "filter_act \<equiv> map fst" \ndefinition schedule where "schedule \<equiv> filter_act o snd" \ndefinition trace where "trace sig \<equiv> filter (\<lambda> a . a \<in> externals sig) o schedule" \ndefinition is_schedule_of where "is_schedule_of A sch \<equiv> (\<exists> e . is_exec_of A e \<and> sch = filter_act (snd e))" \ndefinition is_trace_of where "is_trace_of A tr \<equiv> (\<exists> sch . is_schedule_of A sch \<and> tr = filter (\<lambda> a. a \<in> ext A) sch)" \ndefinition traces where "traces A \<equiv> {tr. is_trace_of A tr}" \nlemma traces_alt: shows "traces A = {tr . \<exists> e . is_exec_of A e \<and> tr = trace (ioa.asig A) e}" \nproof - \n{ \nfix t \nassume a:"t \<in> traces A" \nhave "\<exists> e . is_exec_of A e \<and> trace (ioa.asig A) e = t" \nproof - \nfrom a \nobtain sch where 1:"is_schedule_of A sch" and 2:"t = filter (\<lambda> a. a \<in> ext A) sch" \nby (auto simp add:traces_def is_trace_of_def) \nfrom 1 \nobtain e where 3:"is_exec_of A e" and 4:"sch = filter_act (snd e)" \nby (auto simp add:is_schedule_of_def) \nfrom 4 and 2 \nhave "trace (ioa.asig A) e = t" \nby (simp add:trace_def schedule_def) \nwith 3 \nshow ?thesis \nby fast \nqed \n} \nmoreover \n{ \nfix e \nassume "is_exec_of A e" \nhence "trace (ioa.asig A) e \<in> traces A" \nby (force simp add:trace_def schedule_def traces_def is_trace_of_def is_schedule_of_def is_exec_of_def) \n} \nultimately \nshow ?thesis \nby blast \nqed \nlemmas trace_simps = traces_def is_trace_of_def is_schedule_of_def filter_act_def is_exec_of_def trace_def schedule_def \ndefinition proj_trace::"'a trace \<Rightarrow> ('a signature) \<Rightarrow> 'a trace" (infixr "\<bar>" 12) where "proj_trace t sig \<equiv> filter (\<lambda> a . a \<in> actions sig) t" \ndefinition ioa_implements :: "('s1,'a)ioa \<Rightarrow> ('s2,'a)ioa \<Rightarrow> bool" (infixr "=<|" 12) where "A =<| B \<equiv> inp A = inp B \<and> out A = out B \<and> traces A \<subseteq> traces B" \nsubsection \<open>Operations on Executions\<close> \ndefinition cons_exec where "cons_exec e p \<equiv> (fst e, (snd e)#p)" \ndefinition append_exec where "append_exec e e' \<equiv> (fst e, (snd e)@(snd e'))" \nfun last_state where "last_state (s,[]) = s" | "last_state (s,ps#p) = snd p" \nlemma last_state_reachable: fixes A e assumes "is_exec_of A e" shows "reachable A (last_state e)" \nusing assms \nproof - \nhave "is_exec_of A e \<Longrightarrow> reachable A (last_state e)" \nproof (induction "snd e" arbitrary: e) \ncase Nil \nfrom Nil.prems \nhave 1:"fst e \<in> start A" \nby (simp add:is_exec_of_def) \nfrom Nil.hyps \nhave 2:"last_state e = fst e" \nby (metis last_state.simps(1) surjective_pairing) \nfrom 1 and 2 and Nil.hyps \nshow ?case \nby (metis reachable_0) \nnext \ncase (Cons p ps e) \nlet ?e' = "(fst e, ps)" \nhave ih:"reachable A (last_state ?e')" \nproof - \nfrom Cons.prems and Cons.hyps(2) \nhave "is_exec_of A ?e'" \nby (simp add:is_exec_of_def) (metis (full_types) IOA.is_exec_frag_of.simps(1) IOA.is_exec_frag_of.simps(3) neq_Nil_conv prod.collapse) \nwith Cons.hyps(1) \nshow ?thesis \nby auto \nqed \nfrom Cons.prems and Cons.hyps(2) \nhave "(last_state ?e')\<midarrow>(fst p)\<midarrow>A\<longrightarrow>(snd p)" \nby (simp add:is_exec_of_def) (cases "(A,fst e,ps#p)" rule:is_exec_frag_of.cases, auto) \nwith ih and Cons.hyps(2) \nshow ?case \nby (metis last_state.simps(2) reachable.simps surjective_pairing) \nqed \nthus ?thesis \nusing assms \nby fastforce \nqed \nlemma trans_from_last_state: assumes "is_exec_frag_of A e" and "(last_state e)\<midarrow>a\<midarrow>A\<longrightarrow>s'" shows "is_exec_frag_of A (cons_exec e (a,s'))" \nusing assms \nby (cases "(A, fst e, snd e)" rule:is_exec_frag_of.cases, auto simp add:cons_exec_def) \nlemma exec_frag_prefix: fixes A p ps assumes "is_exec_frag_of A (cons_exec e p)" shows "is_exec_frag_of A e" \nusing assms \nby (cases "(A, fst e, snd e)" rule:is_exec_frag_of.cases, auto simp add:cons_exec_def) \nlemma trace_same_ext: fixes A B e assumes "ext A = ext B" shows "trace (ioa.asig A) e = trace (ioa.asig B) e" \nusing assms \nby (auto simp add:trace_def) \nlemma trace_append_is_append_trace: fixes e e' sig shows "trace sig (append_exec e' e) = trace sig e' @ trace sig e" \nby (simp add:append_exec_def trace_def schedule_def filter_act_def) \nlemma append_exec_frags_is_exec_frag: fixes e e' A as assumes "is_exec_frag_of A e" and "last_state e = fst e'" and "is_exec_frag_of A e'" shows "is_exec_frag_of A (append_exec e e')" \nproof - \nfrom assms \nshow ?thesis \nproof (induct "(fst e',snd e')" arbitrary:e' rule:is_exec_frag_of.induct) \ncase (3 A) \nfrom "3.hyps" and "3.prems"(1) \nshow ?case \nby (simp add:append_exec_def) \nnext \ncase (2 A p) \nhave "last_state e \<midarrow>(fst p)\<midarrow>A\<longrightarrow> snd p" \nusing "2.prems"(2,3) and "2.hyps" \nby (metis is_exec_frag_of.simps(2) prod.collapse) \nhence "is_exec_frag_of A (fst e, (snd e)#p)" \nusing "2.prems"(1) \nby (metis cons_exec_def prod.collapse trans_from_last_state) \nmoreover \nhave "append_exec e e' = (fst e, (snd e)#p)" \nusing "2.hyps" \nby (metis append_Cons append_Nil append_exec_def) \nultimately \nshow ?case \nby auto \nnext \ncase (1 A ps p' p e') \nhave "is_exec_frag_of A (fst e, (snd e)@((ps#p')#p))" \nproof - \nhave "is_exec_frag_of A (fst e, (snd e)@(ps#p'))" \nby (metis "1.hyps" "1.prems" append_exec_def cons_exec_def exec_frag_prefix fst_conv prod_eqI snd_conv) \nmoreover \nhave "snd p' \<midarrow>(fst p)\<midarrow>A\<longrightarrow> snd p" \nusing "1.prems"(3) "1.hyps"(2) \nby (metis is_exec_frag_of.simps(1) prod.collapse) \nultimately \nshow ?thesis \nby simp \nqed \nmoreover \nhave "append_exec e e' = (fst e, (snd e)@((ps#p')#p))" \nby (metis "1.hyps"(2) append_exec_def) \nultimately \nshow ?case \nby simp \nqed \nqed [/INST]\nusing assms \nby (cases e' rule:last_state.cases, auto simp add:append_exec_def) \nend \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma exec_cons: "s \<star> (rs # r)= (s \<star> rs) \<bullet> r" \nby simp \nlemma exec_append: "(s \<star> rs) \<star> rs' = s \<star> (rs@rs')" \nproof (induct rs') \nshow "(s \<star> rs) \<star> [] = s \<star> (rs@[])" \nby simp \nnext \nfix rs' r \nassume ih:"(s \<star> rs) \<star> rs' = s \<star> (rs@rs')" \nthus "(s \<star> rs) \<star> (rs'#r) = s \<star> (rs @ (rs'#r))" \nby (metis append_Cons exec_cons) \nqed \nlemma trans: assumes "s1 \<preceq> s2" and "s2 \<preceq> s3" shows "s1 \<preceq> s3" \nusing assms \nby (auto simp add:less_eq_def, metis exec_append) \nlemma contains_star: fixes s r rs assumes "contains s r" shows "contains (s \<star> rs) r" \nproof (induct rs) \ncase Nil \nshow "contains (s \<star> []) r" \nusing assms \nby auto \nnext \ncase (Cons r' rs) \nwith this \nobtain rs' where 1:"s \<star> rs = \<bottom> \<star> rs'" and 2:"r \<in> set rs'" \nby (auto simp add:contains_def) \nhave 3:"s \<star> (rs#r') = \<bottom>\<star>(rs'#r')" \nusing 1 \nby fastforce \nshow "contains (s \<star> (rs#r')) r" \nusing 2 3 \nby (auto simp add:contains_def) (metis exec_cons rev_subsetD set_subset_Cons) \nqed \nlemma preceq_star: "s \<star> (rs#r) \<preceq> s' \<Longrightarrow> s \<star> rs \<preceq> s'" \nby (metis pre_RDR.exec.simps(1) pre_RDR.exec.simps(2) pre_RDR.less_eq_def trans) \nend \nsubsection \<open>The RDR locale\<close> \nlocale RDR = pre_RDR + assumes idem1:"contains s r \<Longrightarrow> s \<bullet> r = s" and idem2:"\<And> s r r' . fst r \<noteq> fst r' \<Longrightarrow> \<gamma> s r = \<gamma> ((s \<bullet> r) \<bullet> r') r" and antisym:"\<And> s1 s2 . s1 \<preceq> s2 \<and> s2 \<preceq> s1 \<Longrightarrow> s1 = s2" and glb_exists:"\<And> s1 s2 . \<exists> s . is_glb s s1 s2" and consistency:"\<And>s1 s2 s3 rs . s1 \<preceq> s2 \<Longrightarrow> s2 \<preceq> s3 \<Longrightarrow> s3 = s1 \<star> rs \<Longrightarrow> \<exists> rs' rs'' . s2 = s1 \<star> rs' \<and> s3 = s2 \<star> rs'' \<and> set rs' \<subseteq> set rs \<and> set rs'' \<subseteq> set rs" and bot:"\<And> s . \<bottom> \<preceq> s" begin \nlemma inf_glb:"is_glb (s1 \<sqinter> s2) s1 s2" \nproof - \n{ \nfix s s' \nassume "is_glb s s1 s2" and "is_glb s' s1 s2" \nhence "s = s'" \nusing antisym \nby (auto simp add:is_glb_def is_lb_def) \n} \nfrom this and glb_exists \nshow ?thesis \nby (auto simp add:inf_def, metis (lifting) theI') \nqed \nsublocale ordering less_eq less \nproof \nfix s \nshow "s \<preceq> s" \nby (metis exec.simps(1) less_eq_def) \nnext \nfix s s' \nshow "s \<prec> s' = (s \<preceq> s' \<and> s \<noteq> s')" \nby (auto simp add:less_def) \nnext \nfix s s' \nassume "s \<preceq> s'" and "s' \<preceq> s" \nthus "s = s'" \nusing antisym \nby auto \nnext \nfix s1 s2 s3 \nassume "s1 \<preceq> s2" and "s2 \<preceq> s3" \nthus "s1 \<preceq> s3" \nusing trans \nby blast \nqed \nsublocale semilattice_set inf \nproof \nfix s \nshow "s \<sqinter> s = s" \nusing inf_glb \nby (metis antisym is_glb_def is_lb_def refl) \nnext \nfix s1 s2 \nshow "s1 \<sqinter> s2 = (s2 \<sqinter> s1)" \nusing inf_glb \nby (smt antisym is_glb_def pre_RDR.is_lb_def) \nnext \nfix s1 s2 s3 \nshow "(s1 \<sqinter> s2) \<sqinter> s3 = (s1 \<sqinter> (s2 \<sqinter> s3))" \nusing inf_glb \nby(auto simp add:is_glb_def is_lb_def, smt antisym trans) \nqed \nsublocale semilattice_order_set inf less_eq less \nproof \nfix s s' \nshow "s \<preceq> s' = (s = s \<sqinter> s')" \nby (metis antisym idem inf_glb pre_RDR.is_glb_def pre_RDR.is_lb_def) \nnext \nfix s s' \nshow "s \<prec> s' = (s = s \<sqinter> s' \<and> s \<noteq> s')" \nby (metis inf_glb local.antisym local.refl pre_RDR.is_glb_def pre_RDR.is_lb_def pre_RDR.less_def) \nqed \nnotation F ("\<Sqinter> _" [99]) \nsubsection \<open>Some useful lemmas\<close> \nlemma idem_star: fixes r s rs assumes "contains s r" shows "s \<star> rs = s \<star> (filter (\<lambda> x . x \<noteq> r) rs)" \nproof (induct rs) \ncase Nil \nshow "s \<star> [] = s \<star> (filter (\<lambda> x . x \<noteq> r) [])" \nusing assms \nby auto \nnext \ncase (Cons r' rs) \nhave 1:"contains (s \<star> rs) r" \nusing assms and contains_star \nby auto \nshow "s \<star> (rs#r') = s \<star> (filter (\<lambda> x . x \<noteq> r) (rs#r'))" \nproof (cases "r' = r") \ncase True \nhence "s \<star> (rs#r') = s \<star> rs" \nusing idem1 1 \nby auto \nthus ?thesis \nusing Cons \nby simp \nnext \ncase False \nthus ?thesis \nusing Cons \nby auto \nqed \nqed \nlemma idem_star2: fixes s rs' shows "\<exists> rs' . s \<star> rs = s \<star> rs' \<and> set rs' \<subseteq> set rs \<and> (\<forall> r \<in> set rs' . \<not> contains s r)" \nproof (induct rs) \ncase Nil \nthus "\<exists> rs' . s \<star> [] = s \<star> rs' \<and> set rs' \<subseteq> set [] \<and> (\<forall> r \<in> set rs' . \<not> contains s r)" \nby force \nnext \ncase (Cons r rs) \nobtain rs' where 1:"s \<star> rs = s \<star> rs'" and 2:"set rs' \<subseteq> set rs" and 3:"\<forall> r \<in> set rs' . \<not> contains s r" \nusing Cons(1) \nby blast \nshow "\<exists> rs' . s \<star> (rs#r) = s \<star> rs' \<and> set rs' \<subseteq> set (rs#r) \<and> (\<forall> r \<in> set rs' . \<not> contains s r)" \nproof (cases "contains s r") \ncase True \nhave "s\<star>(rs#r) = s\<star>rs'" \nproof - \nhave "s \<star> (rs#r) = s\<star>rs" \nusing True \nby (metis contains_star exec_cons idem1) \nmoreover \nhave "s \<star> (rs'#r) = s\<star>rs'" \nusing True \nby (metis contains_star exec_cons idem1) \nultimately \nshow ?thesis \nusing 1 \nby simp \nqed \nmoreover \nhave "set rs' \<subseteq> set (rs#r)" \nusing 2 \nby (simp, metis subset_insertI2) \nmoreover \nhave "\<forall> r \<in> set rs' . \<not> contains s r" \nusing 3 \nby assumption \nultimately \nshow ?thesis \nby blast \nnext \ncase False \nhave "s\<star>(rs#r) = s\<star>(rs'#r)" \nusing 1 \nby simp \nmoreover \nhave "set (rs'#r) \<subseteq> set (rs#r)" \nusing 2 \nby auto \nmoreover \nhave "\<forall> r \<in> set (rs'#r) . \<not> contains s r" \nusing 3 False \nby auto \nultimately \nshow ?thesis \nby blast \nqed \nqed \nlemma idem2_star: assumes "contains s r" and "\<And> r' . r' \<in> set rs \<Longrightarrow> fst r' \<noteq> fst r" shows "\<gamma> s r = \<gamma> (s \<star> rs) r" \nusing assms \nproof (induct rs) \ncase Nil \nshow "\<gamma> s r = \<gamma> (s \<star> []) r" \nby simp \nnext \ncase (Cons r' rs) \nthus "\<gamma> s r = \<gamma> (s \<star> (rs#r')) r" \nusing assms \nby auto (metis contains_star fst_conv idem1 idem2 prod.exhaust) \nqed \nlemma glb_common: fixes s1 s2 s rs1 rs2 assumes "s1 = s \<star> rs1" and "s2 = s \<star> rs2" shows "\<exists> rs . s1 \<sqinter> s2 = s \<star> rs \<and> set rs \<subseteq> set rs1 \<union> set rs2" \nproof - \nhave 1:"s \<preceq> s1" and 2:"s \<preceq> s2" \nusing assms \nby (auto simp add:less_eq_def) \nhence 3:"s \<preceq> s1 \<sqinter> s2" \nby (metis inf_glb is_lb_def pre_RDR.is_glb_def) \nhave 4:"s1 \<sqinter> s2 \<preceq> s1" \nby (metis cobounded1) \nshow ?thesis \nusing 3 4 assms(1) and consistency \nby blast \nqed [/INST]\nusing assms \nproof (induct ss rule:finite_ne_induct) \ncase (singleton s) \nobtain rs where "s = s0 \<star> rs \<and> set rs \<subseteq> rset" \nusing singleton \nby force \nmoreover \nhave "\<Sqinter> {s} = s" \nusing singleton \nby auto \nultimately \nshow "\<exists> rs . \<Sqinter> {s} = s0 \<star> rs \<and> set rs \<subseteq> rset" \nby blast \nnext \ncase (insert s ss) \nhave 1:"\<And> s' . s' \<in> ss \<Longrightarrow> \<exists> rs . s' = s0 \<star> rs \<and> set rs \<subseteq> rset" \nusing insert(5) \nby force \nobtain rs where 2:"\<Sqinter> ss = s0 \<star> rs" and 3:"set rs \<subseteq> rset" \nusing insert(4) 1 \nby blast \nobtain rs' where 4:"s = s0 \<star> rs'"and 5:"set rs' \<subseteq> rset" \nusing insert(5) \nby blast \nhave 6:"\<Sqinter> (insert s ss) = s \<sqinter> (\<Sqinter> ss)" \nby (metis insert.hyps(1-3) insert_not_elem) \nobtain rs'' where 7:"\<Sqinter> (insert s ss) = s0 \<star> rs''" and 8:"set rs'' \<subseteq> set rs' \<union> set rs" \nusing glb_common 2 4 6 \nby force \nhave 9:"set rs'' \<subseteq> rset" \nusing 3 5 8 \nby blast \nshow "\<exists> rs . \<Sqinter> (insert s ss) = s0 \<star> rs \<and> set rs \<subseteq> rset" \nusing 7 9 \nby blast \nqed \nend \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma step_eq_traces: fixes e_B' A e e_A' a t defines "e_A \<equiv> append_exec e_A' e" and "e_B \<equiv> cons_exec e_B' (a,t)" and "tr \<equiv> trace (ioa.asig A) e" assumes 1:"trace (ioa.asig A) e_A' = trace (ioa.asig A) e_B'" and 2:"if a \<in> ext A then tr = [a] else tr = []" shows "trace (ioa.asig A) e_A = trace (ioa.asig A) e_B" \nproof - \nhave 3:"trace (ioa.asig A) e_B = (if a \<in> ext A then (trace (ioa.asig A) e_B') # a else trace (ioa.asig A) e_B')" \nusing e_B_def \nby (simp add:trace_def schedule_def filter_act_def cons_exec_def) \nhave 4:"trace (ioa.asig A) e_A = (if a \<in> ext A then trace (ioa.asig A) e_A' # a else trace (ioa.asig A) e_A')" \nusing 2 trace_append_is_append_trace[of "ioa.asig A" e_A' e] \nby(auto simp add:e_A_def tr_def split: if_split_asm) \nshow ?thesis \nusing 1 3 4 \nby simp \nqed \nlemma exec_inc_imp_trace_inc: fixes A B assumes "ext B = ext A" and "\<And> e_B . is_exec_of B e_B \<Longrightarrow> \<exists> e_A . is_exec_of A e_A \<and> trace (ioa.asig A) e_A = trace (ioa.asig A) e_B" shows "traces B \<subseteq> traces A" \nproof - \n{ \nfix t \nassume "t \<in> traces B" \nwith this \nobtain e where 1:"t = trace (ioa.asig B) e" and 2:"is_exec_of B e" \nusing traces_alt assms(1) \nby blast \nfrom 1 and assms(1) \nhave 3:"t = trace (ioa.asig A) e" \nby (simp add:trace_def) \nfrom 2 3 and assms(2) \nobtain e' where "is_exec_of A e' \<and> trace (ioa.asig A) e' = trace (ioa.asig A) e" \nby blast \nhence "t \<in> traces A" \nusing 3 traces_alt \nby fastforce \n} \nthus ?thesis \nby fast \nqed \nsubsection \<open>Soundness of Refinement Mappings\<close> \nlemma ref_map_execs: fixes A::"('sA,'a)ioa" and B::"('sB,'a)ioa" and f::"'sB \<Rightarrow> 'sA" and e_B assumes "is_ref_map f B A" and "is_exec_of B e_B" shows "\<exists> e_A . is_exec_of A e_A \<and> trace (ioa.asig A) e_A = trace (ioa.asig A) e_B" \nproof - \nnote assms(2) \nhence "\<exists> e_A . is_exec_of A e_A \<and> trace (ioa.asig A) e_A = trace (ioa.asig A) e_B \<and> last_state e_A = f (last_state e_B)" \nproof (induction "snd e_B" arbitrary:e_B) \ncase Nil \nlet ?e_A = "(f (fst e_B), [])" \nhave "\<And> s . s \<in> start B \<Longrightarrow> f s \<in> start A" \nusing assms(1) \nby (simp add:is_ref_map_def) \nhence "is_exec_of A ?e_A" \nusing Nil.prems(1) \nby (simp add:is_exec_of_def) \nmoreover \nhave "trace (ioa.asig A) ?e_A = trace (ioa.asig A) e_B" \nusing Nil.hyps \nby (simp add:trace_simps) \nmoreover \nhave "last_state ?e_A = f (last_state e_B)" \nusing Nil.hyps \nby (metis last_state.simps(1) prod.collapse) \nultimately \nshow ?case \nby fast \nnext \ncase (Cons p ps e_B) \nlet ?e_B' = "(fst e_B, ps)" \nlet ?s = "last_state ?e_B'" \nlet ?t = "snd p" \nlet ?a = "fst p" \nhave 1:"is_exec_of B ?e_B'" and 2:"?s\<midarrow>?a\<midarrow>B\<longrightarrow>?t" \nusing Cons.prems and Cons.hyps(2) \nby (simp_all add:is_exec_of_def, cases "(B,fst e_B,ps#p)" rule:is_exec_frag_of.cases, auto, cases "(B,fst e_B,ps#p)" rule:is_exec_frag_of.cases, auto) \nwith Cons.hyps(1) \nobtain e_A' where ih1:"is_exec_of A e_A'" and ih2:"trace (ioa.asig A) e_A' = trace (ioa.asig A) ?e_B'" and ih3:"last_state e_A' = f ?s" \nby fastforce \nfrom 1 \nhave 3:"reachable B ?s" \nusing last_state_reachable \nby fast \nobtain e where 4:"fst e = f ?s" and 5:"last_state e = f ?t" and 6:"is_exec_frag_of A e" and 7:"let tr = trace (ioa.asig A) e in if ?a \<in> ext A then tr = [?a] else tr = []" \nusing 2 and 3 and assms(1) \nby (force simp add:is_ref_map_def refines_def) \nlet ?e_A = "append_exec e_A' e" \nhave "is_exec_of A ?e_A" \nusing ih1 ih3 4 6 append_exec_frags_is_exec_frag[of A e e_A'] \nby (metis append_exec_def append_exec_frags_is_exec_frag fst_conv is_exec_of_def) \nmoreover \nhave "trace (ioa.asig A) ?e_A = trace (ioa.asig A) e_B" \nusing ih2 Cons.hyps(2) 7 step_eq_traces[of A e_A' ?e_B' ?a e] \nby (auto simp add:cons_exec_def) (metis prod.collapse) \nmoreover \nhave "last_state ?e_A = f ?t" \nusing ih3 4 5 last_state_of_append \nby metis \nultimately \nshow ?case \nusing Cons.hyps(2) \nby (metis last_state.simps(2) surjective_pairing) \nqed \nthus ?thesis \nby blast \nqed \ntheorem ref_map_soundness: fixes A::"('sA,'a)ioa" and B::"('sB,'a)ioa" and f::"'sB \<Rightarrow> 'sA" assumes "is_ref_map f B A" and "ext A = ext B" shows "traces B \<subseteq> traces A" \nusing assms ref_map_execs exec_inc_imp_trace_inc \nby metis \nsubsection \<open>Soundness of Forward Simulations\<close> \nlemma forward_sim_execs: fixes A::"('sA,'a)ioa" and B::"('sB,'a)ioa" and f::"'sB \<Rightarrow> 'sA set" and e_B assumes "is_forward_sim f B A" and "is_exec_of B e_B" shows "\<exists> e_A . is_exec_of A e_A \<and> trace (ioa.asig A) e_A = trace (ioa.asig A) e_B" \nproof - \nnote assms(2) \nhence "\<exists> e_A . is_exec_of A e_A \<and> trace (ioa.asig A) e_A = trace (ioa.asig A) e_B \<and> last_state e_A \<in> f (last_state e_B)" \nproof (induction "snd e_B" arbitrary:e_B) \ncase Nil \nhave "\<And> s . s \<in> start B \<Longrightarrow> f s \<inter> start A \<noteq> {}" \nusing assms(1) \nby (simp add:is_forward_sim_def) \nwith this \nobtain s' where 1:"s' \<in> f (fst e_B)" and 2:"s' \<in> start A" \nby (metis Int_iff Nil.prems all_not_in_conv is_exec_of_def) \nlet ?e_A = "(s', [])" \nhave "is_exec_of A ?e_A" \nusing 2 \nby (simp add:is_exec_of_def) \nmoreover \nhave "trace (ioa.asig A) ?e_A = trace (ioa.asig A) e_B" \nusing Nil.hyps \nby (simp add:trace_def schedule_def filter_act_def) \nmoreover \nhave "last_state ?e_A \<in> f (last_state e_B)" \nusing Nil.hyps 1 \nby (metis last_state.simps(1) surjective_pairing) \nultimately \nshow ?case \nby fast \nnext \ncase (Cons p ps e_B) \nlet ?e_B' = "(fst e_B, ps)" \nlet ?s = "last_state ?e_B'" \nlet ?t = "snd p" \nlet ?a = "fst p" \nhave 1:"is_exec_of B ?e_B'" and 2:"?s\<midarrow>?a\<midarrow>B\<longrightarrow>?t" \nusing Cons.prems and Cons.hyps(2) \nby (simp_all add:is_exec_of_def, cases "(B,fst e_B,ps#p)" rule:is_exec_frag_of.cases, auto, cases "(B,fst e_B,ps#p)" rule:is_exec_frag_of.cases, auto) \nwith Cons.hyps(1) \nobtain e_A' where ih1:"is_exec_of A e_A'" and ih2:"trace (ioa.asig A) e_A' = trace (ioa.asig A) ?e_B'" and ih3:"last_state e_A' \<in> f ?s" \nby fastforce \nfrom 1 \nhave 3:"reachable B ?s" \nusing last_state_reachable \nby fast \nobtain e where 4:"fst e = last_state e_A'" and 5:"last_state e \<in> f ?t" and 6:"is_exec_frag_of A e" and 7:"let tr = trace (ioa.asig A) e in if ?a \<in> ext A then tr = [?a] else tr = []" \nusing 2 3 assms(1) ih3 \nby (simp add:is_forward_sim_def) (metis prod.collapse prod.inject) \nlet ?e_A = "append_exec e_A' e" \nhave "is_exec_of A ?e_A" \nusing ih1 ih3 4 6 append_exec_frags_is_exec_frag[of A e e_A'] \nby (metis append_exec_def append_exec_frags_is_exec_frag fst_conv is_exec_of_def) \nmoreover \nhave "trace (ioa.asig A) ?e_A = trace (ioa.asig A) e_B" \nusing ih2 Cons.hyps(2) 7 step_eq_traces[of A e_A' ?e_B' ?a e] \nby (auto simp add:cons_exec_def Let_def) (metis prod.collapse) \nmoreover \nhave "last_state ?e_A \<in> f ?t" \nusing ih3 4 5 last_state_of_append \nby metis \nultimately \nshow ?case \nusing Cons.hyps(2) \nby (metis last_state.simps(2) surjective_pairing) \nqed \nthus ?thesis \nby blast \nqed \ntheorem forward_sim_soundness: fixes A::"('sA,'a)ioa" and B::"('sB,'a)ioa" and f::"'sB \<Rightarrow> 'sA set" assumes "is_forward_sim f B A" and "ext A = ext B" shows "traces B \<subseteq> traces A" \nusing assms forward_sim_execs exec_inc_imp_trace_inc \nby metis \nsubsection \<open>Soundness of Backward Simulations\<close> \nlemma backward_sim_execs: fixes A::"('sA,'a)ioa" and B::"('sB,'a)ioa" and f::"'sB \<Rightarrow> 'sA set" and e_B assumes "is_backward_sim f B A" and "is_exec_of B e_B" shows "\<exists> e_A . is_exec_of A e_A \<and> trace (ioa.asig A) e_A = trace (ioa.asig A) e_B" \nproof - \nnote assms(2) \nhence "\<forall> s \<in> f (last_state e_B). \<exists> e_A . is_exec_of A e_A \<and> trace (ioa.asig A) e_A = trace (ioa.asig A) e_B \<and> last_state e_A = s" \nproof (induction "snd e_B" arbitrary:e_B) \ncase Nil \n{ \nfix s' \nassume 1:"s' \<in> f(last_state e_B)" \nhave 2:"\<And> s . s \<in> start B \<Longrightarrow> f s \<subseteq> start A " \nusing assms(1) \nby (simp add:is_backward_sim_def) \nfrom Nil 1 2 \nhave 3:"s' \<in> start A" \nby (metis (full_types) is_exec_of_def last_state.simps(1) subsetD surjective_pairing) \nlet ?e_A = "(s', [])" \nhave 4:"is_exec_of A ?e_A" \nusing 3 \nby (simp add:is_exec_of_def) \nhave 5:"trace (ioa.asig A) ?e_A = trace (ioa.asig A) e_B" \nusing Nil.hyps \nby (simp add:trace_def schedule_def filter_act_def) \nhave 6:"last_state ?e_A \<in> f (last_state e_B)" \nusing Nil.hyps 1 \nby (metis last_state.simps(1)) \nnote 4 5 6 \n} \nthus ?case \nby fastforce \nnext \ncase (Cons p ps e_B) \n{ \nfix t' \nassume 8:"t' \<in> f (last_state e_B)" \nlet ?e_B' = "(fst e_B, ps)" \nlet ?s = "last_state ?e_B'" \nlet ?t = "snd p" \nlet ?a = "fst p" \nhave 5:"?t = last_state e_B" \nusing Cons.hyps(2) \nby (metis last_state.simps(2) prod.collapse) \nhave 1:"is_exec_of B ?e_B'" and 2:"?s\<midarrow>?a\<midarrow>B\<longrightarrow>?t" \nusing Cons.prems and Cons.hyps(2) \nby (simp_all add:is_exec_of_def, cases "(B,fst e_B, ps#p)" rule:is_exec_frag_of.cases, auto, cases "(B,fst e_B, ps#p)" rule:is_exec_frag_of.cases, auto) \nfrom 1 \nhave 3:"reachable B ?s" \nusing last_state_reachable \nby fast \nobtain e where 4:"fst e \<in> f ?s" and 5:"last_state e = t'" and 6:"is_exec_frag_of A e" and 7:"let tr = trace (ioa.asig A) e in if ?a \<in> ext A then tr = [?a] else tr = []" \nusing 2 assms(1) 8 5 3 \nby (auto simp add: is_backward_sim_def, metis) \nobtain e_A' where ih1:"is_exec_of A e_A'" and ih2:"trace (ioa.asig A) e_A' = trace (ioa.asig A) ?e_B'" and ih3:"last_state e_A' = fst e" \nusing 1 4 Cons.hyps(1) \nby (metis snd_conv) \nlet ?e_A = "append_exec e_A' e" \nhave "is_exec_of A ?e_A" \nusing ih1 ih3 4 6 append_exec_frags_is_exec_frag[of A e e_A'] \nby (metis append_exec_def append_exec_frags_is_exec_frag fst_conv is_exec_of_def) \nmoreover \nhave "trace (ioa.asig A) ?e_A = trace (ioa.asig A) e_B" \nusing ih2 Cons.hyps(2) 7 step_eq_traces[of A e_A' ?e_B' ?a e] \nby (auto simp add:cons_exec_def Let_def) (metis prod.collapse) \nmoreover \nhave "last_state ?e_A = t'" \nusing ih3 5 last_state_of_append \nby metis \nultimately \nhave "\<exists> e_A . is_exec_of A e_A \<and> trace (ioa.asig A) e_A = trace (ioa.asig A) e_B \<and> last_state e_A = t'" \nby blast \n} \nthus ?case \nby blast \nqed \nmoreover \nfrom assms(1) \nhave total:"\<And> s . f s \<noteq> {}" \nby (simp add:is_backward_sim_def) \nultimately \nshow ?thesis \nby fast \nqed [/INST]\nusing assms backward_sim_execs exec_inc_imp_trace_inc \nby metis \nend \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma strengthen_pre: "\<lbrakk> \<forall>z s. P' z s \<longrightarrow> P z s; C \<turnstile>\<^sub>t {P}c{Q} \<rbrakk> \<Longrightarrow> C \<turnstile>\<^sub>t {P'}c{Q}" \nby(rule thoare.Conseq, assumption, blast) \nlemma weaken_post: "\<lbrakk> C \<turnstile>\<^sub>t {P}c{Q}; \<forall>z s. Q z s \<longrightarrow> Q' z s \<rbrakk> \<Longrightarrow> C \<turnstile>\<^sub>t {P}c{Q'}" \nby(erule thoare.Conseq, blast) \nlemmas tvalid_defs = tvalid_def ctvalid_def valids_def cvalids_def valid_defs \nlemma [iff]: "(\<Turnstile>\<^sub>t {\<lambda>z s. \<exists>n. P n z s}c{Q}) = (\<forall>n. \<Turnstile>\<^sub>t {P n}c{Q})" \napply(unfold tvalid_defs) \napply fast \ndone \nlemma [iff]: "(\<Turnstile>\<^sub>t {\<lambda>z s. P z s \<and> P'}c{Q}) = (P' \<longrightarrow> \<Turnstile>\<^sub>t {P}c{Q})" \napply(unfold tvalid_defs) \napply fast \ndone \nlemma [iff]: "(\<Turnstile>\<^sub>t {P}CALL p{Q}) = (\<Turnstile>\<^sub>t {P}body p{Q})" \napply(unfold tvalid_defs) \napply fast \ndone \nlemma unfold_while: "(s -WHILE b DO c\<rightarrow> u) = (s -IF b THEN c;WHILE b DO c ELSE Do(\<lambda>s. {s})\<rightarrow> u)" \nby(auto elim: exec.cases intro:exec.intros split:if_split_asm) \ntheorem "C |\<turnstile>\<^sub>t D \<Longrightarrow> C |\<Turnstile>\<^sub>t D" \napply(erule thoare.induct) \napply(simp only:tvalid_defs) \napply fast \napply(simp add:tvalid_defs) \napply fast \napply(simp only:tvalid_defs) \napply clarsimp \nprefer 3 \napply(simp add:tvalid_defs) \napply fast \nprefer 3 \napply(simp add:tvalid_defs) \napply blast \napply(simp add:tvalid_defs) \napply(rule impI, rule conjI) \napply(rule allI) \napply(erule wf_induct) \napply clarify \napply(drule unfold_while[THEN iffD1]) \napply (simp split: if_split_asm) \napply fast \napply(rule allI, rule allI) \napply(erule wf_induct) \napply clarify \napply(case_tac "b x") \nprefer 2 \napply (erule termi.WhileFalse) \napply(rule termi.WhileTrue, assumption) \napply fast \napply (subgoal_tac "(t,x):r") \napply fast \napply blast \ndefer \napply(simp add:tvalid_defs) \napply fast \napply(simp (no_asm_use) add:tvalid_defs) \napply fast \napply(simp add:tvalid_defs) \napply fast \napply(simp (no_asm_use) add:valids_def ctvalid_def cvalids_def) \napply(rule allI) \napply(rename_tac q) \napply(subgoal_tac "\<forall>pre. \<Turnstile>\<^sub>t {\<lambda>z s. P (fst(q,pre)) z s & s=(snd(q,pre))} body (fst(q,pre)) {Q (fst(q,pre))}") \napply(simp (no_asm_use) add:tvalid_defs) \napply fast \napply(rule allI) \napply(erule_tac wf_induct) \napply(simp add:split_paired_all) \napply(rename_tac q pre) \napply(erule allE, erule allE, erule conjE, erule impE) \nprefer 2 \napply assumption \napply(rotate_tac 1, erule thin_rl) \napply(unfold tvalid_defs) \napply fast \ndone \ndefinition MGT\<^sub>t :: "com \<Rightarrow> state assn \<times> com \<times> state assn" where [simp]: "MGT\<^sub>t c = (\<lambda>z s. z = s \<and> c\<down>s, c, \<lambda>z t. z -c\<rightarrow> t)" \nlemma MGT_implies_complete: "{} |\<turnstile>\<^sub>t {MGT\<^sub>t c} \<Longrightarrow> {} \<Turnstile>\<^sub>t {P}c{Q} \<Longrightarrow> {} \<turnstile>\<^sub>t {P}c{Q::state assn}" \napply(unfold MGT\<^sub>t_def) \napply (erule thoare.Conseq) \napply(simp add: tvalid_defs) \napply blast \ndone \nlemma while_termiE: "\<lbrakk> WHILE b DO c \<down> s; b s \<rbrakk> \<Longrightarrow> c \<down> s" \nby(erule termi.cases, auto) \nlemma while_termiE2: "\<lbrakk> WHILE b DO c \<down> s; b s; s -c\<rightarrow> t \<rbrakk> \<Longrightarrow> WHILE b DO c \<down> t" \nby(erule termi.cases, auto) \nlemma MGT_lemma: "\<forall>p. {} |\<turnstile>\<^sub>t {MGT\<^sub>t(CALL p)} \<Longrightarrow> {} |\<turnstile>\<^sub>t {MGT\<^sub>t c}" \napply (simp) \napply(induct_tac c) \napply (rule strengthen_pre[OF _ thoare.Do]) \napply blast \napply(rename_tac com1 com2) \napply(rule_tac Q = "\<lambda>z s. z -com1\<rightarrow>s & com2\<down>s" in thoare.Semi) \napply(erule thoare.Conseq) \napply fast \napply(erule thoare.Conseq) \napply fast \napply(rule thoare.If) \napply(erule thoare.Conseq) \napply simp \napply(erule thoare.Conseq) \napply simp \ndefer \napply simp \napply(fast intro:thoare.Local elim!: thoare.Conseq) \napply(rename_tac b c) \napply(rule_tac P' = "\<lambda>z s. (z,s) \<in> ({(s,t). b s \<and> s -c\<rightarrow> t})^* \<and> WHILE b DO c \<down> s" in thoare.Conseq) \napply(rule_tac thoare.While[OF wf_termi]) \napply(rule allI) \napply(erule thoare.Conseq) \napply(fastforce intro:rtrancl_into_rtrancl dest:while_termiE while_termiE2) \napply(rule conjI) \napply clarsimp \napply(erule_tac x = s in allE) \napply clarsimp \napply(erule converse_rtrancl_induct) \napply(erule exec.WhileFalse) \napply(fast elim:exec.WhileTrue) \napply(fast intro: rtrancl_refl) \ndone \ninductive_set exec1 :: "((com list \<times> state) \<times> (com list \<times> state))set" and exec1' :: "(com list \<times> state) \<Rightarrow> (com list \<times> state) \<Rightarrow> bool" ("_ \<rightarrow> _" [81,81] 100) where "cs0 \<rightarrow> cs1 \<equiv> (cs0,cs1) : exec1" | Do[iff]: "t \<in> f s \<Longrightarrow> ((Do f)#cs,s) \<rightarrow> (cs,t)" | Semi[iff]: "((c1;c2)#cs,s) \<rightarrow> (c1#c2#cs,s)" | IfTrue: "b s \<Longrightarrow> ((IF b THEN c1 ELSE c2)#cs,s) \<rightarrow> (c1#cs,s)" | IfFalse: "\<not>b s \<Longrightarrow> ((IF b THEN c1 ELSE c2)#cs,s) \<rightarrow> (c2#cs,s)" | WhileFalse: "\<not>b s \<Longrightarrow> ((WHILE b DO c)#cs,s) \<rightarrow> (cs,s)" | WhileTrue: "b s \<Longrightarrow> ((WHILE b DO c)#cs,s) \<rightarrow> (c#(WHILE b DO c)#cs,s)" | Call[iff]: "(CALL p#cs,s) \<rightarrow> (body p#cs,s)" | Local[iff]: "((LOCAL f;c;g)#cs,s) \<rightarrow> (c # Do(\<lambda>t. {g s t})#cs, f s)" \nabbreviation exectr :: "(com list \<times> state) \<Rightarrow> (com list \<times> state) \<Rightarrow> bool" ("_ \<rightarrow>\<^sup>* _" [81,81] 100) where "cs0 \<rightarrow>\<^sup>* cs1 \<equiv> (cs0,cs1) : exec1^*" \ninductive_cases exec1E[elim!]: "([],s) \<rightarrow> (cs',s')" "(Do f#cs,s) \<rightarrow> (cs',s')" "((c1;c2)#cs,s) \<rightarrow> (cs',s')" "((IF b THEN c1 ELSE c2)#cs,s) \<rightarrow> (cs',s')" "((WHILE b DO c)#cs,s) \<rightarrow> (cs',s')" "(CALL p#cs,s) \<rightarrow> (cs',s')" "((LOCAL f;c;g)#cs,s) \<rightarrow> (cs',s')" \nlemma [iff]: "\<not> ([],s) \<rightarrow> u" \nby (induct u) blast \nlemma app_exec: "(cs,s) \<rightarrow> (cs',s') \<Longrightarrow> (cs@cs2,s) \<rightarrow> (cs'@cs2,s')" \napply(erule exec1.induct) \napply(simp_all del:fun_upd_apply) \napply(blast intro:exec1.intros)+ \ndone \nlemma app_execs: "(cs,s) \<rightarrow>\<^sup>* (cs',s') \<Longrightarrow> (cs@cs2,s) \<rightarrow>\<^sup>* (cs'@cs2,s')" \napply(erule rtrancl_induct2) \napply blast \napply(blast intro:app_exec rtrancl_trans) \ndone \nlemma exec_impl_execs[rule_format]: "s -c\<rightarrow> s' \<Longrightarrow> \<forall>cs. (c#cs,s) \<rightarrow>\<^sup>* (cs,s')" \napply(erule exec.induct) \napply blast \napply(blast intro:rtrancl_trans) \napply(blast intro:exec1.IfTrue rtrancl_trans) \napply(blast intro:exec1.IfFalse rtrancl_trans) \napply(blast intro:exec1.WhileFalse rtrancl_trans) \napply(blast intro:exec1.WhileTrue rtrancl_trans) \napply(blast intro: rtrancl_trans) \napply(blast intro: rtrancl_trans) \ndone \ninductive execs :: "state \<Rightarrow> com list \<Rightarrow> state \<Rightarrow> bool" ("_/ =_\<Rightarrow>/ _" [50,0,50] 50) where "s =[]\<Rightarrow> s" | "s -c\<rightarrow> t \<Longrightarrow> t =cs\<Rightarrow> u \<Longrightarrow> s =c#cs\<Rightarrow> u" \ninductive_cases [elim!]: "s =[]\<Rightarrow> t" "s =c#cs\<Rightarrow> t" \ntheorem exec1s_impl_execs: "(cs,s) \<rightarrow>\<^sup>* ([],t) \<Longrightarrow> s =cs\<Rightarrow> t" \napply(erule converse_rtrancl_induct2) \napply(rule execs.intros) \napply(erule exec1.cases) \napply(blast intro:execs.intros) \napply(blast intro:execs.intros) \napply(fastforce intro:execs.intros) \napply(fastforce intro:execs.intros) \napply(blast intro:execs.intros exec.intros)+ \ndone \ntheorem exec1s_impl_exec: "([c],s) \<rightarrow>\<^sup>* ([],t) \<Longrightarrow> s -c\<rightarrow> t" \nby(blast dest: exec1s_impl_execs) \nprimrec termis :: "com list \<Rightarrow> state \<Rightarrow> bool" (infixl "\<Down>" 60) where "[]\<Down>s = True" | "c#cs \<Down> s = (c\<down>s \<and> (\<forall>t. s -c\<rightarrow> t \<longrightarrow> cs\<Down>t))" \nlemma exec1_pres_termis: "(cs,s) \<rightarrow> (cs',s') \<Longrightarrow> cs\<Down>s \<longrightarrow> cs'\<Down>s'" \napply(erule exec1.induct) \napply(simp_all del:fun_upd_apply) \napply blast \napply(blast intro:exec.WhileFalse) \napply(blast intro:while_termiE while_termiE2 exec.WhileTrue) \napply blast \ndone \nlemma execs_pres_termis: "(cs,s) \<rightarrow>\<^sup>* (cs',s') \<Longrightarrow> cs\<Down>s \<longrightarrow> cs'\<Down>s'" \napply(erule rtrancl_induct2) \napply blast \napply(blast dest:exec1_pres_termis) \ndone \nlemma execs_pres_termi: "\<lbrakk> ([c],s) \<rightarrow>\<^sup>* (c'#cs',s'); c\<down>s \<rbrakk> \<Longrightarrow> c'\<down>s'" \napply(insert execs_pres_termis[of "[c]" _ "c'#cs'",simplified]) \napply blast \ndone \ndefinition termi_call_steps :: "((pname \<times> state) \<times> (pname \<times> state))set" where "termi_call_steps = {((q,t),(p,s)). body p\<down>s \<and> (\<exists>cs. ([body p], s) \<rightarrow>\<^sup>* (CALL q# cs, t))}" \nlemma lem: "\<forall>y. (a,y)\<in>r\<^sup>+ \<longrightarrow> P a \<longrightarrow> P y \<Longrightarrow> ((b,a) \<in> {(y,x). P x \<and> (x,y)\<in>r}\<^sup>+) = ((b,a) \<in> {(y,x). P x \<and> (x,y)\<in>r\<^sup>+})" \napply(rule iffI) \napply clarify \napply(erule trancl_induct) \napply blast \napply(blast intro:trancl_trans) \napply clarify \napply(erule trancl_induct) \napply blast \napply(blast intro:trancl_trans) \ndone \nlemma renumber_aux: "\<lbrakk>\<forall>i. (a,f i) \<in> r^* \<and> (f i,f(Suc i)) : r; (a,b) : r^* \<rbrakk> \<Longrightarrow> b = f 0 \<longrightarrow> (\<exists>f. f 0 = a & (\<forall>i. (f i, f(Suc i)) : r))" \napply(erule converse_rtrancl_induct) \napply blast \napply(clarsimp) \napply(rule_tac x="\<lambda>i. case i of 0 \<Rightarrow> y | Suc i \<Rightarrow> fa i" in exI) \napply simp \napply clarify \napply(case_tac i) \napply simp_all \ndone \nlemma renumber: "\<forall>i. (a,f i) : r^* \<and> (f i,f(Suc i)) : r \<Longrightarrow> \<exists>f. f 0 = a & (\<forall>i. (f i, f(Suc i)) : r)" \nby(blast dest:renumber_aux) \ndefinition inf :: "com list \<Rightarrow> state \<Rightarrow> bool" where "inf cs s \<longleftrightarrow> (\<exists>f. f 0 = (cs,s) \<and> (\<forall>i. f i \<rightarrow> f(Suc i)))" \nlemma [iff]: "\<not> inf [] s" \napply(unfold inf_def) \napply clarify \napply(erule_tac x = 0 in allE) \napply simp \ndone \nlemma [iff]: "\<not> inf [Do f] s" \napply(unfold inf_def) \napply clarify \napply(frule_tac x = 0 in spec) \napply(erule_tac x = 1 in allE) \napply (case_tac "fa (Suc 0)") \napply clarsimp \ndone \nlemma [iff]: "inf ((c1;c2)#cs) s = inf (c1#c2#cs) s" \napply(unfold inf_def) \napply(rule iffI) \napply clarify \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply(frule_tac x = 0 in spec) \napply (case_tac "f (Suc 0)") \napply clarsimp \napply clarify \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((c1;c2)#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp split:nat.split) \ndone \nlemma [iff]: "inf ((IF b THEN c1 ELSE c2)#cs) s = inf ((if b s then c1 else c2)#cs) s" \napply(unfold inf_def) \napply(rule iffI) \napply clarsimp \napply(frule_tac x = 0 in spec) \napply (case_tac "f (Suc 0)") \napply(rule conjI) \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply clarsimp \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((IF b THEN c1 ELSE c2)#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp add: exec1.intros split:nat.split) \ndone \nlemma [simp]: "inf ((WHILE b DO c)#cs) s = (if b s then inf (c#(WHILE b DO c)#cs) s else inf cs s)" \napply(unfold inf_def) \napply(rule iffI) \napply clarsimp \napply(frule_tac x = 0 in spec) \napply (case_tac "f (Suc 0)") \napply(rule conjI) \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply (clarsimp split:if_splits) \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((WHILE b DO c)#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp add: exec1.intros split:nat.split) \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((WHILE b DO c)#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp add: exec1.intros split:nat.split) \ndone \nlemma [iff]: "inf (CALL p#cs) s = inf (body p#cs) s" \napply(unfold inf_def) \napply(rule iffI) \napply clarsimp \napply(frule_tac x = 0 in spec) \napply (case_tac "f (Suc 0)") \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply clarsimp \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> (CALL p#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp add: exec1.intros split:nat.split) \ndone \nlemma [iff]: "inf ((LOCAL f;c;g)#cs) s = inf (c#Do(\<lambda>t. {g s t})#cs) (f s)" \napply(unfold inf_def) \napply(rule iffI) \napply clarsimp \napply(rename_tac F) \napply(frule_tac x = 0 in spec) \napply (case_tac "F (Suc 0)") \napply clarsimp \napply(rule_tac x = "\<lambda>i. F(Suc i)" in exI) \napply clarsimp \napply (clarsimp) \napply(rename_tac F) \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((LOCAL f;c;g)#cs,s) | Suc i \<Rightarrow> F i" in exI) \napply(simp add: exec1.intros split:nat.split) \ndone \nlemma exec1_only1_aux: "(ccs,s) \<rightarrow> (cs',t) \<Longrightarrow> \<forall>c cs. ccs = c#cs \<longrightarrow> (\<exists>cs1. cs' = cs1 @ cs)" \napply(erule exec1.induct) \napply force+ \ndone \nlemma exec1_only1: "(c#cs,s) \<rightarrow> (cs',t) \<Longrightarrow> \<exists>cs1. cs' = cs1 @ cs" \nby(blast dest:exec1_only1_aux) \nlemma exec1_drop_suffix_aux: "(cs12,s) \<rightarrow> (cs1'2,s') \<Longrightarrow> \<forall>cs1 cs2 cs1'. cs12 = cs1@cs2 & cs1'2 = cs1'@cs2 & cs1 \<noteq> [] \<longrightarrow> (cs1,s) \<rightarrow> (cs1',s')" \napply(erule exec1.induct) \napply (force intro:exec1.intros simp add: neq_Nil_conv)+ \ndone \nlemma exec1_drop_suffix: "(cs1@cs2,s) \<rightarrow> (cs1'@cs2,s') \<Longrightarrow> cs1 \<noteq> [] \<Longrightarrow> (cs1,s) \<rightarrow> (cs1',s')" \nby(blast dest:exec1_drop_suffix_aux) \nlemma execs_drop_suffix[rule_format(no_asm)]: "\<lbrakk> f 0 = (c#cs,s);\<forall>i. f(i) \<rightarrow> f(Suc i) \<rbrakk> \<Longrightarrow> (\<forall>i<k. p i \<noteq> [] & fst(f i) = p i@cs) \<longrightarrow> fst(f k) = p k@cs \<longrightarrow> ([c],s) \<rightarrow>\<^sup>* (p k,snd(f k))" \napply(induct_tac k) \napply simp \napply (clarsimp) \napply(erule rtrancl_into_rtrancl) \napply(erule_tac x = n in allE) \napply(erule_tac x = n in allE) \napply(case_tac "f n") \napply(case_tac "f(Suc n)") \napply simp \napply(blast dest:exec1_drop_suffix) \ndone \nlemma execs_drop_suffix0: "\<lbrakk> f 0 = (c#cs,s);\<forall>i. f(i) \<rightarrow> f(Suc i); \<forall>i<k. p i \<noteq> [] & fst(f i) = p i@cs; fst(f k) = cs; p k = [] \<rbrakk> \<Longrightarrow> ([c],s) \<rightarrow>\<^sup>* ([],snd(f k))" \napply(drule execs_drop_suffix,assumption,assumption) \napply simp \napply simp \ndone \nlemma skolemize1: "\<forall>x. P x \<longrightarrow> (\<exists>y. Q x y) \<Longrightarrow> \<exists>f.\<forall>x. P x \<longrightarrow> Q x (f x)" \napply(rule_tac x = "\<lambda>x. SOME y. Q x y" in exI) \napply(fast intro:someI2) \ndone \nlemma least_aux: "\<lbrakk>f 0 = (c # cs, s); \<forall>i. f i \<rightarrow> f (Suc i); fst(f k) = cs; \<forall>i<k. fst(f i) \<noteq> cs\<rbrakk> \<Longrightarrow> \<forall>i \<le> k. (\<exists>p. (p \<noteq> []) = (i < k) & fst(f i) = p @ cs)" \napply(rule allI) \napply(induct_tac i) \napply simp \napply (rule ccontr) \napply simp \napply clarsimp \napply(drule order_le_imp_less_or_eq) \napply(erule disjE) \nprefer 2 \napply simp \napply simp \napply(erule_tac x = n in allE) \napply(erule_tac x = "Suc n" in allE) \napply(case_tac "f n") \napply(case_tac "f(Suc n)") \napply simp \napply(rename_tac sn csn1 sn1) \napply (clarsimp simp add: neq_Nil_conv) \napply(drule exec1_only1) \napply (clarsimp simp add: neq_Nil_conv) \napply(erule disjE) \napply clarsimp \napply clarsimp \napply(case_tac cs1) \napply simp \napply simp \ndone \nlemma least_lem: "\<lbrakk>f 0 = (c#cs,s); \<forall>i. f i \<rightarrow> f(Suc i); \<exists>i. fst(f i) = cs \<rbrakk> \<Longrightarrow> \<exists>k. fst(f k) = cs & ([c],s) \<rightarrow>\<^sup>* ([],snd(f k))" \napply(rule_tac x="LEAST i. fst(f i) = cs" in exI) \napply(rule conjI) \napply(fast intro: LeastI) \napply(subgoal_tac "\<forall>i\<le>LEAST i. fst (f i) = cs. \<exists>p. ((p \<noteq> []) = (i<(LEAST i. fst (f i) = cs))) & fst(f i) = p@cs") \napply(drule skolemize1) \napply clarify \napply(rename_tac p) \napply(erule_tac p=p in execs_drop_suffix0, assumption) \napply (blast dest:order_less_imp_le) \napply(fast intro: LeastI) \napply(erule thin_rl) \napply(erule_tac x = "LEAST j. fst (f j) = fst (f i)" in allE) \napply blast \napply(erule least_aux,assumption) \napply(fast intro: LeastI) \napply clarify \napply(drule not_less_Least) \napply blast \ndone \nlemma skolemize2: "\<forall>x.\<exists>y. P x y \<Longrightarrow> \<exists>f.\<forall>x. P x (f x)" \napply(rule_tac x = "\<lambda>x. SOME y. P x y" in exI) \napply(fast intro:someI2) \ndone \nlemma inf_cases: "inf (c#cs) s \<Longrightarrow> inf [c] s \<or> (\<exists>t. s -c\<rightarrow> t \<and> inf cs t)" \napply(unfold inf_def) \napply (clarsimp del: disjCI) \napply(case_tac "\<exists>i. fst(f i) = cs") \napply(rule disjI2) \napply(drule least_lem, assumption, assumption) \napply clarify \napply(drule exec1s_impl_exec) \napply(case_tac "f k") \napply simp \napply (rule exI, rule conjI, assumption) \napply(rule_tac x="\<lambda>i. f(i+k)" in exI) \napply (clarsimp) \napply(rule disjI1) \napply simp \napply(subgoal_tac "\<forall>i. \<exists>p. p \<noteq> [] \<and> fst(f i) = p@cs") \napply(drule skolemize2) \napply clarify \napply(rename_tac p) \napply(rule_tac x = "\<lambda>i. (p i, snd(f i))" in exI) \napply(rule conjI) \napply(erule_tac x = 0 in allE, erule conjE) \napply simp \napply clarify \napply(erule_tac x = i in allE) \napply(erule_tac x = i in allE) \napply(frule_tac x = i in spec) \napply(erule_tac x = "Suc i" in allE) \napply(case_tac "f i") \napply(case_tac "f(Suc i)") \napply clarsimp \napply(blast intro:exec1_drop_suffix) \napply(clarify) \napply(induct_tac i) \napply force \napply clarsimp \napply(case_tac p) \napply blast \napply(erule_tac x=n in allE) \napply(erule_tac x="Suc n" in allE) \napply(case_tac "f n") \napply(case_tac "f(Suc n)") \napply clarsimp \napply(drule exec1_only1) \napply clarsimp \ndone \nlemma termi_impl_not_inf: "c \<down> s \<Longrightarrow> \<not> inf [c] s" \napply(erule termi.induct) \n(*Do*) \napply clarify \n(*Semi*) \napply(blast dest:inf_cases) \n(* Cond *) \napply clarsimp \napply clarsimp \n(*While*) \napply clarsimp \napply(fastforce dest:inf_cases) \n(*Call*) \napply blast \n(*Local*) \napply(blast dest:inf_cases) \ndone \nlemma termi_impl_no_inf_chain: "c\<down>s \<Longrightarrow> \<not>(\<exists>f. f 0 = ([c],s) \<and> (\<forall>i::nat. (f i, f(i+1)) : exec1^+))" \napply(subgoal_tac "wf({(y,x). ([c],s) \<rightarrow>\<^sup>* x & x \<rightarrow> y}^+)") \napply(simp only:wf_iff_no_infinite_down_chain) \napply(erule contrapos_nn) \napply clarify \napply(subgoal_tac "\<forall>i. ([c], s) \<rightarrow>\<^sup>* f i") \nprefer 2 \napply(rule allI) \napply(induct_tac i) \napply simp \napply simp \napply(blast intro: trancl_into_rtrancl rtrancl_trans) \napply(rule_tac x=f in exI) \napply clarify \napply(drule_tac x=i in spec) \napply(subst lem) \napply(blast intro: trancl_into_rtrancl rtrancl_trans) \napply clarsimp \napply(rule wf_trancl) \napply(simp only:wf_iff_no_infinite_down_chain) \napply(clarify) \napply simp \napply(drule renumber) \napply(fold inf_def) \napply(simp add: termi_impl_not_inf) \ndone \nprimrec cseq :: "(nat \<Rightarrow> pname \<times> state) \<Rightarrow> nat \<Rightarrow> com list" where "cseq S 0 = []" | "cseq S (Suc i) = (SOME cs. ([body(fst(S i))], snd(S i)) \<rightarrow>\<^sup>* (CALL(fst(S(i+1)))# cs, snd(S(i+1)))) @ cseq S i" \nlemma wf_termi_call_steps: "wf termi_call_steps" \napply(unfold termi_call_steps_def) \napply(simp only:wf_iff_no_infinite_down_chain) \napply(clarify) \napply(rename_tac S) \napply simp \napply(subgoal_tac "\<exists>Cs. Cs 0 = [] & (\<forall>i. (body(fst(S i)) # Cs i,snd(S i)) \<rightarrow>\<^sup>* (CALL(fst(S(i+1)))# Cs(i+1), snd(S(i+1))))") \nprefer 2 \napply(rule_tac x = "cseq S" in exI) \napply clarsimp \napply(erule_tac x=i in allE) \napply clarsimp \napply(rename_tac q t p s cs) \napply(erule_tac P = "\<lambda>cs.([body p],s) \<rightarrow>\<^sup>* (CALL q# cs, t)" in someI2) \napply(fastforce dest:app_execs) \napply clarify \napply(subgoal_tac "\<forall>i. ((body(fst(S i))# Cs i,snd(S i)), (body(fst(S(i+1)))# Cs(i+1), snd(S(i+1)))) : exec1^+") \nprefer 2 \napply(blast intro:rtrancl_into_trancl1) \napply(subgoal_tac "\<exists>f. f 0 = ([body(fst(S 0))],snd(S 0)) \<and> (\<forall>i. (f i, f(i+1)) : exec1^+)") \nprefer 2 \napply(rule_tac x = "\<lambda>i.(body(fst(S i))#Cs i,snd(S i))" in exI) \napply blast \napply(erule_tac x=0 in allE) \napply(simp add:split_def) \napply clarify \napply(drule termi_impl_no_inf_chain) \napply simp \napply blast \ndone \nlemma CALL_lemma: "(\<Union>p. {(\<lambda>z s. (z=s \<and> body p\<down>s) \<and> ((p,s),(q,pre)) \<in> termi_call_steps, CALL p, \<lambda>z s. z -body p\<rightarrow> s)}) \<turnstile>\<^sub>t {\<lambda>z s. (z=s \<and> body q\<down>pre) \<and> (\<exists>cs. ([body q],pre) \<rightarrow>\<^sup>* (c#cs,s))} c {\<lambda>z s. z -c\<rightarrow> s}" \napply(induct_tac c) \n(*Do*) \napply (rule strengthen_pre[OF _ thoare.Do]) \napply(blast dest: execs_pres_termi) \n(*Semi*) \napply(rename_tac c1 c2) \napply(rule_tac Q = "\<lambda>z s. body q\<down>pre & (\<exists>cs. ([body q], pre) \<rightarrow>\<^sup>* (c2#cs,s)) & z -c1\<rightarrow>s & c2\<down>s" in thoare.Semi) \napply(erule thoare.Conseq) \napply(rule conjI) \napply clarsimp \napply(subgoal_tac "s -c1\<rightarrow> t") \nprefer 2 \napply(blast intro: exec1.Semi exec_impl_execs rtrancl_trans) \napply(subgoal_tac "([body q], pre) \<rightarrow>\<^sup>* (c2 # cs, t)") \nprefer 2 \napply(blast intro:exec1.Semi[THEN r_into_rtrancl] exec_impl_execs rtrancl_trans) \napply(subgoal_tac "([body q], pre) \<rightarrow>\<^sup>* (c2 # cs, t)") \nprefer 2 \napply(blast intro: exec_impl_execs rtrancl_trans) \napply(blast intro:exec_impl_execs rtrancl_trans execs_pres_termi) \napply(fast intro: exec1.Semi rtrancl_trans) \napply(erule thoare.Conseq) \napply blast \n(*Call*) \nprefer 3 \napply(simp only:termi_call_steps_def) \napply(rule thoare.Conseq[OF thoare.Asm]) \napply blast \napply(blast dest: execs_pres_termi) \n(*If*) \napply(rule thoare.If) \napply(erule thoare.Conseq) \napply simp \napply(blast intro: exec1.IfTrue rtrancl_trans) \napply(erule thoare.Conseq) \napply simp \napply(blast intro: exec1.IfFalse rtrancl_trans) \n(*Local*) \ndefer \napply simp \napply(rule thoare.Local) \napply(rule allI) \napply(erule thoare.Conseq) \napply (clarsimp) \napply(rule conjI) \napply (clarsimp) \napply(drule rtrancl_trans[OF _ r_into_rtrancl[OF exec1.Local]]) \napply(fast) \napply (clarsimp) \napply(drule rtrancl_trans[OF _ r_into_rtrancl[OF exec1.Local]]) \napply blast \n(*While*) \napply(rename_tac b c) \napply(rule_tac P' = "\<lambda>z s. (z,s) \<in> ({(s,t). b s \<and> s -c\<rightarrow> t})^* \<and> body q\<down>pre \<and> (\<exists>cs. ([body q], pre) \<rightarrow>\<^sup>* ((WHILE b DO c) # cs, s))" in thoare.Conseq) \napply(rule_tac thoare.While[OF wf_termi]) \napply(rule allI) \napply(erule thoare.Conseq) \napply clarsimp \napply(rule conjI) \napply clarsimp \napply(rule conjI) \napply(blast intro: rtrancl_trans exec1.WhileTrue) \napply(rule conjI) \napply(rule exI, rule rtrancl_trans, assumption) \napply(blast intro: exec1.WhileTrue exec_impl_execs rtrancl_trans) \napply(rule conjI) \napply(blast intro:execs_pres_termi) \napply(blast intro: exec1.WhileTrue exec_impl_execs rtrancl_trans) \napply(blast intro: exec1.WhileTrue exec_impl_execs rtrancl_trans) \napply(rule conjI) \napply clarsimp \napply(erule_tac x = s in allE) \napply clarsimp \napply(erule impE) \napply blast \napply clarify \napply(erule_tac a=s in converse_rtrancl_induct) \napply(erule exec.WhileFalse) \napply(fast elim:exec.WhileTrue) \napply(fast intro: rtrancl_refl) \ndone \nlemma CALL_cor: "(\<Union>p. {(\<lambda>z s. (z=s \<and> body p\<down>s) \<and> ((p,s),(q,pre)) \<in> termi_call_steps, CALL p, \<lambda>z s. z -body p\<rightarrow> s)}) \<turnstile>\<^sub>t {\<lambda>z s. (z=s \<and> body q\<down>s) \<and> s = pre} body q {\<lambda>z s. z -body q\<rightarrow> s}" \napply(rule strengthen_pre[OF _ CALL_lemma]) \napply blast \ndone \nlemma MGT_CALL: "{} |\<turnstile>\<^sub>t (\<Union>p. {MGT\<^sub>t(CALL p)})" \napply(simp add: MGT\<^sub>t_def) \napply(rule thoare.Call) \napply(rule wf_termi_call_steps) \napply clarify \napply(rule CALL_cor) \ndone \nlemma MGT_CALL1: "\<forall>p. {} |\<turnstile>\<^sub>t {MGT\<^sub>t(CALL p)}" \nby(fastforce intro:MGT_CALL[THEN ConjE]) [/INST]\napply(erule MGT_implies_complete[OF MGT_lemma[OF MGT_CALL1]]) \ndone \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemmas valid_defs = valid_def valids_def cvalids_def nvalid_def nvalids_def cnvalids_def \ntheorem "C \<tturnstile> D \<Longrightarrow> C |\<Turnstile> D" \ntxt\<open>\noindent As before, we prove a generalization of @{prop"C |\<Turnstile> D"}, namely @{prop"\<forall>n. C |\<Turnstile>_n D"}, by induction on @{prop"C \<tturnstile> D"}, with an induction on @{term n} in the @{term CALL} case.\<close> \napply(subgoal_tac "\<forall>n. C |\<Turnstile>_n D") \napply(unfold valid_defs exec_iff_execn[THEN eq_reflection]) \napply fast \napply(erule hoare.induct) \napply simp \napply simp \napply fast \napply simp \napply clarify \napply(drule while_rule) \nprefer 3 \napply (assumption, assumption) \napply simp \napply simp \napply fast \napply(rule allI, rule impI) \napply(induct_tac n) \napply force \napply clarify \napply(frule bspec, assumption) \napply (simp(no_asm_use)) \napply fast \napply simp \napply fast \napply simp \napply fast \napply fast \napply fastforce \ndone \ndefinition MGT :: "com \<Rightarrow> state assn \<times> com \<times> state assn" where [simp]: "MGT c = (\<lambda>z s. z = s, c, \<lambda>z t. z -c\<rightarrow> t)" \nlemma strengthen_pre: "\<lbrakk> \<forall>z s. P' z s \<longrightarrow> P z s; C\<turnstile> {P}c{Q} \<rbrakk> \<Longrightarrow> C\<turnstile> {P'}c{Q}" \nby(rule hoare.Conseq, assumption, blast) \nlemma MGT_implies_complete: "{} \<tturnstile> {MGT c} \<Longrightarrow> \<Turnstile> {P}c{Q} \<Longrightarrow> {} \<turnstile> {P}c{Q::state assn}" \napply(unfold MGT_def) \napply (erule hoare.Conseq) \napply(simp add: valid_defs) \ndone \nlemma MGT_lemma: "\<forall>p. C \<tturnstile> {MGT(CALL p)} \<Longrightarrow> C \<tturnstile> {MGT c}" \napply (simp) \napply(induct_tac c) \napply (rule strengthen_pre[OF _ hoare.Do]) \napply blast \napply simp \napply (rule hoare.Semi) \napply blast \napply (rule hoare.Conseq) \napply blast \napply blast \napply clarsimp \napply(rule hoare.If) \napply(rule hoare.Conseq) \napply blast \napply simp \napply(rule hoare.Conseq) \napply blast \napply simp \nprefer 2 \napply simp \napply(rename_tac b c) \napply(rule hoare.Conseq) \napply(rule_tac P = "\<lambda>z s. (z,s) \<in> ({(s,t). b s \<and> s -c\<rightarrow> t})^*" in hoare.While) \napply(erule hoare.Conseq) \napply(blast intro:rtrancl_into_rtrancl) \napply clarsimp \napply(rename_tac s t) \napply(erule_tac x = s in allE) \napply clarsimp \napply(erule converse_rtrancl_induct) \napply(blast intro:exec.intros) \napply(fast elim:exec.WhileTrue) \napply(fastforce intro: hoare.Local elim!: hoare.Conseq) \ndone \nlemma MGT_body: "(P, CALL p, Q) = MGT (CALL pa) \<Longrightarrow> C \<tturnstile> {MGT (body p)} \<Longrightarrow> C \<turnstile> {P} body p {Q}" \napply clarsimp \ndone \ndeclare MGT_def[simp del] \nlemma MGT_CALL: "{} \<tturnstile> {mgt. \<exists>p. mgt = MGT(CALL p)}" \napply (rule hoare.Call) \napply(fastforce simp add:MGT_def) \napply(rule hoare.ConjI) \napply clarsimp \napply (erule MGT_body) \napply(rule MGT_lemma) \napply(unfold MGT_def) \napply(fast intro: hoare.Asm) \ndone [/INST]\napply(rule MGT_implies_complete) \nprefer 2 \napply assumption \napply (rule MGT_lemma) \napply(rule allI) \napply(unfold MGT_def) \napply(rule hoare.ConjE[OF MGT_CALL]) \napply(simp add:MGT_def fun_eq_iff) \ndone \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma [iff]: "(s -Do f\<rightarrow> t) = (t \<in> f s)" \nby(auto elim: exec.cases intro:exec.intros) \nlemma [iff]: "(s -c;d\<rightarrow> u) = (\<exists>t. s -c\<rightarrow> t \<and> t -d\<rightarrow> u)" \nby(auto elim: exec.cases intro:exec.intros) \nlemma [iff]: "(s -IF b THEN c ELSE d\<rightarrow> t) = (s -if b s then c else d\<rightarrow> t)" \napply(rule iffI) \napply(auto elim: exec.cases intro:exec.intros) \napply(auto intro:exec.intros split:if_split_asm) \ndone \nlemma [iff]: "(s -CALL p\<rightarrow> t) = (s -body p\<rightarrow> t)" \nby(blast elim: exec.cases intro:exec.intros) \nlemma [iff]: "(s -LOCAL f; c; g\<rightarrow> u) = (\<exists>t. f s -c\<rightarrow> t \<and> u = g s t)" \nby(fastforce elim: exec.cases intro:exec.intros) \ninductive execn :: "state \<Rightarrow> com \<Rightarrow> nat \<Rightarrow> state \<Rightarrow> bool" ("_/ -_-_\<rightarrow>/ _" [50,0,0,50] 50) where Do: "t \<in> f s \<Longrightarrow> s -Do f-n\<rightarrow> t" | Semi: "\<lbrakk> s0 -c0-n\<rightarrow> s1; s1 -c1-n\<rightarrow> s2 \<rbrakk> \<Longrightarrow> s0 -c0;c1-n\<rightarrow> s2" | IfTrue: "\<lbrakk> b s; s -c0-n\<rightarrow> t \<rbrakk> \<Longrightarrow> s -IF b THEN c0 ELSE c1-n\<rightarrow> t" | IfFalse: "\<lbrakk> \<not>b s; s -c1-n\<rightarrow> t \<rbrakk> \<Longrightarrow> s -IF b THEN c0 ELSE c1-n\<rightarrow> t" | WhileFalse: "\<not>b s \<Longrightarrow> s -WHILE b DO c-n\<rightarrow> s" | WhileTrue: "\<lbrakk> b s; s -c-n\<rightarrow> t; t -WHILE b DO c-n\<rightarrow> u \<rbrakk> \<Longrightarrow> s -WHILE b DO c-n\<rightarrow> u" | Call: "s -body p-n\<rightarrow> t \<Longrightarrow> s -CALL p-Suc n\<rightarrow> t" | Local: "f s -c-n\<rightarrow> t \<Longrightarrow> s -LOCAL f; c; g-n\<rightarrow> g s t" \nlemma [iff]: "(s -Do f-n\<rightarrow> t) = (t \<in> f s)" \nby(auto elim: execn.cases intro:execn.intros) \nlemma [iff]: "(s -c1;c2-n\<rightarrow> u) = (\<exists>t. s -c1-n\<rightarrow> t \<and> t -c2-n\<rightarrow> u)" \nby(best elim: execn.cases intro:execn.intros) \nlemma [iff]: "(s -IF b THEN c ELSE d-n\<rightarrow> t) = (s -if b s then c else d-n\<rightarrow> t)" \napply auto \napply(blast elim: execn.cases intro:execn.intros)+ \ndone \nlemma [iff]: "(s -CALL p- 0\<rightarrow> t) = False" \nby(blast elim: execn.cases intro:execn.intros) \nlemma [iff]: "(s -CALL p-Suc n\<rightarrow> t) = (s -body p-n\<rightarrow> t)" \nby(blast elim: execn.cases intro:execn.intros) \nlemma [iff]: "(s -LOCAL f; c; g-n\<rightarrow> u) = (\<exists>t. f s -c-n\<rightarrow> t \<and> u = g s t)" \nby(auto elim: execn.cases intro:execn.intros) \nlemma exec_mono[rule_format]: "s -c-m\<rightarrow> t \<Longrightarrow> \<forall>n. m \<le> n \<longrightarrow> s -c-n\<rightarrow> t" \napply(erule execn.induct) \napply(blast) \napply(blast) \napply(simp) \napply(simp) \napply(simp add:execn.intros) \napply(blast intro:execn.intros) \napply(clarify) \napply(rename_tac m) \napply(case_tac m) \napply simp \napply simp \napply blast \ndone \nlemma exec_iff_execn: "(s -c\<rightarrow> t) = (\<exists>n. s -c-n\<rightarrow> t)" \napply(rule iffI) \napply(erule exec.induct) \napply blast \napply clarify \napply(rename_tac m n) \napply(rule_tac x = "max m n" in exI) \napply(fastforce intro:exec.intros exec_mono simp add:max_def) \napply fastforce \napply fastforce \napply(blast intro:execn.intros) \napply clarify \napply(rename_tac m n) \napply(rule_tac x = "max m n" in exI) \napply(fastforce elim:execn.WhileTrue exec_mono simp add:max_def) \napply blast \napply blast \napply(erule exE, erule execn.induct) \napply blast \napply blast \napply fastforce \napply fastforce \napply(erule exec.WhileFalse) \napply(blast intro: exec.intros) \napply blast \napply blast \ndone \nlemma while_lemma[rule_format]: "s -w-n\<rightarrow> t \<Longrightarrow> \<forall>b c. w = WHILE b DO c \<and> P s \<and> (\<forall>s s'. P s \<and> b s \<and> s -c-n\<rightarrow> s' \<longrightarrow> P s') \<longrightarrow> P t \<and> \<not>b t" \napply(erule execn.induct) \napply clarify+ \ndefer \napply clarify+ \napply(subgoal_tac "P t") \napply blast \napply blast \ndone [/INST]\napply(drule while_lemma) \nprefer 2 \napply assumption \napply blast \ndone \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma [iff]: "(Do f \<down> s) = (f s \<noteq> {})" \napply(rule iffI) \nprefer 2 \napply(best intro:termi.intros) \napply(erule termi.cases) \napply blast+ \ndone \nlemma [iff]: "((c1;c2) \<down> s0) = (c1 \<down> s0 \<and> (\<forall>s1. s0 -c1\<rightarrow> s1 \<longrightarrow> c2 \<down> s1))" \napply(rule iffI) \nprefer 2 \napply(best intro:termi.intros) \napply(erule termi.cases) \napply blast+ \ndone \nlemma [iff]: "(IF b THEN c1 ELSE c2 \<down> s) = ((if b s then c1 else c2) \<down> s)" \napply simp \napply(rule conjI) \napply(rule impI) \napply(rule iffI) \nprefer 2 \napply(blast intro:termi.intros) \napply(erule termi.cases) \napply blast+ \napply(rule impI) \napply(rule iffI) \nprefer 2 \napply(blast intro:termi.intros) \napply(erule termi.cases) \napply blast+ \ndone \nlemma [iff]: "(CALL p \<down> s) = (body p \<down> s)" \nby(fast elim: termi.cases intro:termi.intros) \nlemma [iff]: "(LOCAL f;c;g \<down> s) = (c \<down> f s)" \nby(fast elim: termi.cases intro:termi.intros) \nlemma termi_while_lemma[rule_format]: "w\<down>fk \<Longrightarrow> (\<forall>k b c. fk = f k \<and> w = WHILE b DO c \<and> (\<forall>i. f i -c\<rightarrow> f(Suc i)) \<longrightarrow> (\<exists>i. \<not>b(f i)))" \napply(erule termi.induct) \napply simp_all \napply blast \napply blast \ndone \nlemma termi_while: "\<lbrakk> (WHILE b DO c) \<down> f k; \<forall>i. f i -c\<rightarrow> f(Suc i) \<rbrakk> \<Longrightarrow> \<exists>i. \<not>b(f i)" \nby(blast intro:termi_while_lemma) [/INST]\napply(subst wf_iff_no_infinite_down_chain) \napply(rule notI) \napply clarsimp \napply(insert termi_while) \napply blast \ndone \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma "((\<forall>s t. (\<forall>z. P' z s \<longrightarrow> Q' z t) \<longrightarrow> (\<forall>z. P z s \<longrightarrow> Q z t)) \<and> (\<forall>s. (\<exists>z. P z s) \<longrightarrow> (\<exists>z. P' z s))) = (\<forall>z s. P z s \<longrightarrow> (\<forall>t.\<exists>z'. P' z' s \<and> (Q' z' t \<longrightarrow> Q z t)))" \nby blast \ntext\<open>The key difference to the work by Kleymann (and America and de Boer) is that soundness and completeness are shown for arbitrary, i.e.\ unbounded nondeterminism. This is a significant extension and appears to have been an open problem. The details are found below and are explained in a separate paper~\cite{Nipkow-CSL02}.\<close> \nlemma strengthen_pre: "\<lbrakk> \<forall>z s. P' z s \<longrightarrow> P z s; C \<turnstile>\<^sub>t {P}c{Q} \<rbrakk> \<Longrightarrow> C \<turnstile>\<^sub>t {P'}c{Q}" \nby(rule thoare.Conseq, assumption, blast) \nlemma weaken_post: "\<lbrakk> C \<turnstile>\<^sub>t {P}c{Q}; \<forall>z s. Q z s \<longrightarrow> Q' z s \<rbrakk> \<Longrightarrow> C \<turnstile>\<^sub>t {P}c{Q'}" \nby(erule thoare.Conseq, blast) \nlemmas tvalid_defs = tvalid_def ctvalid_def valid_defs \nlemma [iff]: "(\<Turnstile>\<^sub>t {\<lambda>z s. \<exists>n. P n z s}c{Q}) = (\<forall>n. \<Turnstile>\<^sub>t {P n}c{Q})" \napply(unfold tvalid_defs) \napply fast \ndone \nlemma [iff]: "(\<Turnstile>\<^sub>t {\<lambda>z s. P z s \<and> P'}c{Q}) = (P' \<longrightarrow> \<Turnstile>\<^sub>t {P}c{Q})" \napply(unfold tvalid_defs) \napply fast \ndone \nlemma [iff]: "(\<Turnstile>\<^sub>t {P}CALL{Q}) = (\<Turnstile>\<^sub>t {P}body{Q})" \napply(unfold tvalid_defs) \napply fast \ndone \ntheorem "C \<turnstile>\<^sub>t {P}c{Q} \<Longrightarrow> C \<Turnstile>\<^sub>t {P}c{Q}" \napply(erule thoare.induct) \napply(simp only:tvalid_defs) \napply fast \napply(simp only:tvalid_defs) \napply fast \napply(simp only:tvalid_defs) \napply clarsimp \nprefer 3 \napply(simp add:tvalid_defs) \nprefer 3 \napply(simp only:tvalid_defs) \napply blast \napply(simp only:tvalid_defs) \napply(rule impI, rule conjI) \napply(rule allI) \napply(erule wf_induct) \napply clarify \napply(drule unfold_while[THEN iffD1]) \napply (simp split: if_split_asm) \napply fast \napply(rule allI, rule allI) \napply(erule wf_induct) \napply clarify \napply(case_tac "b x") \nprefer 2 \napply (erule termi.WhileFalse) \napply(rule termi.WhileTrue, assumption) \napply fast \napply (subgoal_tac "(t,x):r") \napply fast \napply blast \napply(simp (no_asm_use) add:ctvalid_def) \napply(subgoal_tac "\<forall>n. \<Turnstile>\<^sub>t {\<lambda>z s. P z s \<and> s=n} body {Q}") \napply(simp (no_asm_use) add:tvalid_defs) \napply blast \napply(rule allI) \napply(erule wf_induct) \napply(unfold tvalid_defs) \napply fast \napply fast \ndone \ndefinition MGT\<^sub>t :: "com \<Rightarrow> state assn \<times> com \<times> state assn" where [simp]: "MGT\<^sub>t c = (\<lambda>z s. z = s \<and> c\<down>s, c, \<lambda>z t. z -c\<rightarrow> t)" \nlemma MGT_implies_complete: "{} \<turnstile>\<^sub>t MGT\<^sub>t c \<Longrightarrow> {} \<Turnstile>\<^sub>t {P}c{Q} \<Longrightarrow> {} \<turnstile>\<^sub>t {P}c{Q::state assn}" \napply(simp add: MGT\<^sub>t_def) \napply (erule thoare.Conseq) \napply(simp add: tvalid_defs) \napply blast \ndone \nlemma while_termiE: "\<lbrakk> WHILE b DO c \<down> s; b s \<rbrakk> \<Longrightarrow> c \<down> s" \nby(erule termi.cases, auto) \nlemma while_termiE2: "\<lbrakk> WHILE b DO c \<down> s; b s; s -c\<rightarrow> t \<rbrakk> \<Longrightarrow> WHILE b DO c \<down> t" \nby(erule termi.cases, auto) \nlemma MGT_lemma: "C \<turnstile>\<^sub>t MGT\<^sub>t CALL \<Longrightarrow> C \<turnstile>\<^sub>t MGT\<^sub>t c" \napply (simp) \napply(induct_tac c) \napply (rule strengthen_pre[OF _ thoare.Do]) \napply blast \napply(rename_tac com1 com2) \napply(rule_tac Q = "\<lambda>z s. z -com1\<rightarrow>s & com2\<down>s" in thoare.Semi) \napply(erule thoare.Conseq) \napply fast \napply(erule thoare.Conseq) \napply fast \napply(rule thoare.If) \napply(erule thoare.Conseq) \napply simp \napply(erule thoare.Conseq) \napply simp \ndefer \napply simp \napply(fast intro:thoare.Local elim!: thoare.Conseq) \napply(rename_tac b c) \napply(rule_tac P' = "\<lambda>z s. (z,s) \<in> ({(s,t). b s \<and> s -c\<rightarrow> t})^* \<and> WHILE b DO c \<down> s" in thoare.Conseq) \napply(rule_tac thoare.While[OF wf_termi]) \napply(rule allI) \napply(erule thoare.Conseq) \napply(fastforce intro:rtrancl_into_rtrancl dest:while_termiE while_termiE2) \napply(rule conjI) \napply clarsimp \napply(erule_tac x = s in allE) \napply clarsimp \napply(erule converse_rtrancl_induct) \napply simp \napply(fast elim:exec.WhileTrue) \napply(fast intro: rtrancl_refl) \ndone \ninductive_set exec1 :: "((com list \<times> state) \<times> (com list \<times> state))set" and exec1' :: "(com list \<times> state) \<Rightarrow> (com list \<times> state) \<Rightarrow> bool" ("_ \<rightarrow> _" [81,81] 100) where "cs0 \<rightarrow> cs1 \<equiv> (cs0,cs1) : exec1" | Do[iff]: "t \<in> f s \<Longrightarrow> ((Do f)#cs,s) \<rightarrow> (cs,t)" | Semi[iff]: "((c1;c2)#cs,s) \<rightarrow> (c1#c2#cs,s)" | IfTrue: "b s \<Longrightarrow> ((IF b THEN c1 ELSE c2)#cs,s) \<rightarrow> (c1#cs,s)" | IfFalse: "\<not>b s \<Longrightarrow> ((IF b THEN c1 ELSE c2)#cs,s) \<rightarrow> (c2#cs,s)" | WhileFalse: "\<not>b s \<Longrightarrow> ((WHILE b DO c)#cs,s) \<rightarrow> (cs,s)" | WhileTrue: "b s \<Longrightarrow> ((WHILE b DO c)#cs,s) \<rightarrow> (c#(WHILE b DO c)#cs,s)" | Call[iff]: "(CALL#cs,s) \<rightarrow> (body#cs,s)" | Local[iff]: "((LOCAL f;c;g)#cs,s) \<rightarrow> (c # Do(\<lambda>t. {g s t})#cs, f s)" \nabbreviation exectr :: "(com list \<times> state) \<Rightarrow> (com list \<times> state) \<Rightarrow> bool" ("_ \<rightarrow>\<^sup>* _" [81,81] 100) where "cs0 \<rightarrow>\<^sup>* cs1 \<equiv> (cs0,cs1) : exec1^*" \ninductive_cases exec1E[elim!]: "([],s) \<rightarrow> (cs',s')" "(Do f#cs,s) \<rightarrow> (cs',s')" "((c1;c2)#cs,s) \<rightarrow> (cs',s')" "((IF b THEN c1 ELSE c2)#cs,s) \<rightarrow> (cs',s')" "((WHILE b DO c)#cs,s) \<rightarrow> (cs',s')" "(CALL#cs,s) \<rightarrow> (cs',s')" "((LOCAL f;c;g)#cs,s) \<rightarrow> (cs',s')" \nlemma [iff]: "\<not> ([],s) \<rightarrow> u" \nby (induct u) blast \nlemma app_exec: "(cs,s) \<rightarrow> (cs',s') \<Longrightarrow> (cs@cs2,s) \<rightarrow> (cs'@cs2,s')" \napply(erule exec1.induct) \napply(simp_all del:fun_upd_apply) \napply(blast intro:exec1.intros)+ \ndone \nlemma app_execs: "(cs,s) \<rightarrow>\<^sup>* (cs',s') \<Longrightarrow> (cs@cs2,s) \<rightarrow>\<^sup>* (cs'@cs2,s')" \napply(erule rtrancl_induct2) \napply blast \napply(blast intro:app_exec rtrancl_trans) \ndone \nlemma exec_impl_execs[rule_format]: "s -c\<rightarrow> s' \<Longrightarrow> \<forall>cs. (c#cs,s) \<rightarrow>\<^sup>* (cs,s')" \napply(erule exec.induct) \napply blast \napply(blast intro:rtrancl_trans) \napply(blast intro:exec1.IfTrue rtrancl_trans) \napply(blast intro:exec1.IfFalse rtrancl_trans) \napply(blast intro:exec1.WhileFalse rtrancl_trans) \napply(blast intro:exec1.WhileTrue rtrancl_trans) \napply(blast intro: rtrancl_trans) \napply(blast intro: rtrancl_trans) \ndone \ninductive execs :: "state \<Rightarrow> com list \<Rightarrow> state \<Rightarrow> bool" ("_/ =_\<Rightarrow>/ _" [50,0,50] 50) where "s =[]\<Rightarrow> s" | "s -c\<rightarrow> t \<Longrightarrow> t =cs\<Rightarrow> u \<Longrightarrow> s =c#cs\<Rightarrow> u" \ninductive_cases [elim!]: "s =[]\<Rightarrow> t" "s =c#cs\<Rightarrow> t" \ntheorem exec1s_impl_execs: "(cs,s) \<rightarrow>\<^sup>* ([],t) \<Longrightarrow> s =cs\<Rightarrow> t" \napply(erule converse_rtrancl_induct2) \napply(rule execs.intros) \napply(erule exec1.cases) \napply(blast intro:execs.intros) \napply(blast intro:execs.intros) \napply(fastforce intro:execs.intros) \napply(fastforce intro:execs.intros) \napply(blast intro:execs.intros exec.intros) \napply(blast intro:execs.intros exec.intros) \napply(blast intro:execs.intros exec.intros) \napply(blast intro:execs.intros exec.intros) \ndone \ntheorem exec1s_impl_exec: "([c],s) \<rightarrow>\<^sup>* ([],t) \<Longrightarrow> s -c\<rightarrow> t" \nby(blast dest: exec1s_impl_execs) \nprimrec termis :: "com list \<Rightarrow> state \<Rightarrow> bool" (infixl "\<Down>" 60) where "[]\<Down>s = True" | "c#cs \<Down> s = (c\<down>s \<and> (\<forall>t. s -c\<rightarrow> t \<longrightarrow> cs\<Down>t))" \nlemma exec1_pres_termis: "(cs,s) \<rightarrow> (cs',s') \<Longrightarrow> cs\<Down>s \<longrightarrow> cs'\<Down>s'" \napply(erule exec1.induct) \napply(simp_all) \napply blast \napply(blast intro:while_termiE while_termiE2 exec.WhileTrue) \napply blast \ndone \nlemma execs_pres_termis: "(cs,s) \<rightarrow>\<^sup>* (cs',s') \<Longrightarrow> cs\<Down>s \<longrightarrow> cs'\<Down>s'" \napply(erule rtrancl_induct2) \napply blast \napply(blast dest:exec1_pres_termis) \ndone \nlemma execs_pres_termi: "\<lbrakk> ([c],s) \<rightarrow>\<^sup>* (c'#cs',s'); c\<down>s \<rbrakk> \<Longrightarrow> c'\<down>s'" \napply(insert execs_pres_termis[of "[c]" _ "c'#cs'",simplified]) \napply blast \ndone \ndefinition termi_call_steps :: "(state \<times> state)set" where "termi_call_steps = {(t,s). body\<down>s \<and> (\<exists>cs. ([body], s) \<rightarrow>\<^sup>* (CALL # cs, t))}" \nlemma lem: "\<forall>y. (a,y)\<in>r\<^sup>+ \<longrightarrow> P a \<longrightarrow> P y \<Longrightarrow> ((b,a) \<in> {(y,x). P x \<and> (x,y):r}\<^sup>+) = ((b,a) \<in> {(y,x). P x \<and> (x,y)\<in>r\<^sup>+})" \napply(rule iffI) \napply clarify \napply(erule trancl_induct) \napply blast \napply(blast intro:trancl_trans) \napply clarify \napply(erule trancl_induct) \napply blast \napply(blast intro:trancl_trans) \ndone \nlemma renumber_aux: "\<lbrakk>\<forall>i. (a,f i) : r^* \<and> (f i,f(Suc i)) : r; (a,b) : r^* \<rbrakk> \<Longrightarrow> b = f 0 \<longrightarrow> (\<exists>f. f 0 = a & (\<forall>i. (f i, f(Suc i)) : r))" \napply(erule converse_rtrancl_induct) \napply blast \napply(clarsimp) \napply(rule_tac x="\<lambda>i. case i of 0 \<Rightarrow> y | Suc i \<Rightarrow> fa i" in exI) \napply simp \napply clarify \napply(case_tac i) \napply simp_all \ndone \nlemma renumber: "\<forall>i. (a,f i) : r^* \<and> (f i,f(Suc i)) : r \<Longrightarrow> \<exists>f. f 0 = a & (\<forall>i. (f i, f(Suc i)) : r)" \nby(blast dest:renumber_aux) \ndefinition inf :: "com list \<Rightarrow> state \<Rightarrow> bool" where "inf cs s \<longleftrightarrow> (\<exists>f. f 0 = (cs,s) \<and> (\<forall>i. f i \<rightarrow> f(Suc i)))" \nlemma [iff]: "\<not> inf [] s" \napply(unfold inf_def) \napply clarify \napply(erule_tac x = 0 in allE) \napply simp \ndone \nlemma [iff]: "\<not> inf [Do f] s" \napply(unfold inf_def) \napply clarify \napply(frule_tac x = 0 in spec) \napply(erule_tac x = 1 in allE) \napply(case_tac "fa (Suc 0)") \napply clarsimp \ndone \nlemma [iff]: "inf ((c1;c2)#cs) s = inf (c1#c2#cs) s" \napply(unfold inf_def) \napply(rule iffI) \napply clarify \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply(frule_tac x = 0 in spec) \napply(case_tac "f (Suc 0)") \napply clarsimp \napply clarify \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((c1;c2)#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp split:nat.split) \ndone \nlemma [iff]: "inf ((IF b THEN c1 ELSE c2)#cs) s = inf ((if b s then c1 else c2)#cs) s" \napply(unfold inf_def) \napply(rule iffI) \napply clarsimp \napply(frule_tac x = 0 in spec) \napply (case_tac "f (Suc 0)") \napply(rule conjI) \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply clarsimp \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((IF b THEN c1 ELSE c2)#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp add: exec1.intros split:nat.split) \ndone \nlemma [simp]: "inf ((WHILE b DO c)#cs) s = (if b s then inf (c#(WHILE b DO c)#cs) s else inf cs s)" \napply(unfold inf_def) \napply(rule iffI) \napply clarsimp \napply(frule_tac x = 0 in spec) \napply (case_tac "f (Suc 0)") \napply(rule conjI) \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply (clarsimp split:if_splits) \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((WHILE b DO c)#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp add: exec1.intros split:nat.split) \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((WHILE b DO c)#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp add: exec1.intros split:nat.split) \ndone \nlemma [iff]: "inf (CALL#cs) s = inf (body#cs) s" \napply(unfold inf_def) \napply(rule iffI) \napply clarsimp \napply(frule_tac x = 0 in spec) \napply (case_tac "f (Suc 0)") \napply clarsimp \napply(rule_tac x = "\<lambda>i. f(Suc i)" in exI) \napply clarsimp \napply clarsimp \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> (CALL#cs,s) | Suc i \<Rightarrow> f i" in exI) \napply(simp add: exec1.intros split:nat.split) \ndone \nlemma [iff]: "inf ((LOCAL f;c;g)#cs) s = inf (c#Do(\<lambda>t. {g s t})#cs) (f s)" \napply(unfold inf_def) \napply(rule iffI) \napply clarsimp \napply(rename_tac F) \napply(frule_tac x = 0 in spec) \napply (case_tac "F (Suc 0)") \napply clarsimp \napply(rule_tac x = "\<lambda>i. F(Suc i)" in exI) \napply clarsimp \napply (clarsimp) \napply(rename_tac F) \napply(rule_tac x = "\<lambda>i. case i of 0 \<Rightarrow> ((LOCAL f;c;g)#cs,s) | Suc i \<Rightarrow> F i" in exI) \napply(simp add: exec1.intros split:nat.split) \ndone \nlemma exec1_only1_aux: "(ccs,s) \<rightarrow> (cs',t) \<Longrightarrow> \<forall>c cs. ccs = c#cs \<longrightarrow> (\<exists>cs1. cs' = cs1 @ cs)" \napply(erule exec1.induct) \napply blast \napply force+ \ndone \nlemma exec1_only1: "(c#cs,s) \<rightarrow> (cs',t) \<Longrightarrow> \<exists>cs1. cs' = cs1 @ cs" \nby(blast dest:exec1_only1_aux) \nlemma exec1_drop_suffix_aux: "(cs12,s) \<rightarrow> (cs1'2,s') \<Longrightarrow> \<forall>cs1 cs2 cs1'. cs12 = cs1@cs2 & cs1'2 = cs1'@cs2 & cs1 \<noteq> [] \<longrightarrow> (cs1,s) \<rightarrow> (cs1',s')" \napply(erule exec1.induct) \napply (force intro:exec1.intros simp add: neq_Nil_conv)+ \ndone \nlemma exec1_drop_suffix: "(cs1@cs2,s) \<rightarrow> (cs1'@cs2,s') \<Longrightarrow> cs1 \<noteq> [] \<Longrightarrow> (cs1,s) \<rightarrow> (cs1',s')" \nby(blast dest:exec1_drop_suffix_aux) \nlemma execs_drop_suffix[rule_format(no_asm)]: "\<lbrakk> f 0 = (c#cs,s);\<forall>i. f(i) \<rightarrow> f(Suc i) \<rbrakk> \<Longrightarrow> (\<forall>i<k. p i \<noteq> [] & fst(f i) = p i@cs) \<longrightarrow> fst(f k) = p k@cs \<longrightarrow> ([c],s) \<rightarrow>\<^sup>* (p k,snd(f k))" \napply(induct_tac k) \napply simp \napply (clarsimp) \napply(erule rtrancl_into_rtrancl) \napply(erule_tac x = n in allE) \napply(erule_tac x = n in allE) \napply(case_tac "f n") \napply(case_tac "f(Suc n)") \napply simp \napply(blast dest:exec1_drop_suffix) \ndone \nlemma execs_drop_suffix0: "\<lbrakk> f 0 = (c#cs,s);\<forall>i. f(i) \<rightarrow> f(Suc i); \<forall>i<k. p i \<noteq> [] & fst(f i) = p i@cs; fst(f k) = cs; p k = [] \<rbrakk> \<Longrightarrow> ([c],s) \<rightarrow>\<^sup>* ([],snd(f k))" \napply(drule execs_drop_suffix,assumption,assumption) \napply simp \napply simp \ndone \nlemma skolemize1: "\<forall>x. P x \<longrightarrow> (\<exists>y. Q x y) \<Longrightarrow> \<exists>f.\<forall>x. P x \<longrightarrow> Q x (f x)" \napply(rule_tac x = "\<lambda>x. SOME y. Q x y" in exI) \napply(fast intro:someI2) \ndone \nlemma least_aux: "\<lbrakk>f 0 = (c # cs, s); \<forall>i. f i \<rightarrow> f (Suc i); fst(f k) = cs; \<forall>i<k. fst(f i) \<noteq> cs\<rbrakk> \<Longrightarrow> \<forall>i \<le> k. (\<exists>p. (p \<noteq> []) = (i < k) & fst(f i) = p @ cs)" \napply(rule allI) \napply(induct_tac i) \napply simp \napply (rule ccontr) \napply simp \napply clarsimp \napply(drule order_le_imp_less_or_eq) \napply(erule disjE) \nprefer 2 \napply simp \napply simp \napply(erule_tac x = n in allE) \napply(erule_tac x = "Suc n" in allE) \napply(case_tac "f n") \napply(case_tac "f(Suc n)") \napply simp \napply(rename_tac sn csn1 sn1) \napply (clarsimp simp add: neq_Nil_conv) \napply(drule exec1_only1) \napply (clarsimp simp add: neq_Nil_conv) \napply(erule disjE) \napply clarsimp \napply clarsimp \napply(case_tac cs1) \napply simp \napply simp \ndone \nlemma least_lem: "\<lbrakk>f 0 = (c#cs,s); \<forall>i. f i \<rightarrow> f(Suc i); \<exists>i. fst(f i) = cs \<rbrakk> \<Longrightarrow> \<exists>k. fst(f k) = cs & ([c],s) \<rightarrow>\<^sup>* ([],snd(f k))" \napply(rule_tac x="LEAST i. fst(f i) = cs" in exI) \napply(rule conjI) \napply(fast intro: LeastI) \napply(subgoal_tac "\<forall>i\<le>LEAST i. fst (f i) = cs. \<exists>p. ((p \<noteq> []) = (i<(LEAST i. fst (f i) = cs))) & fst(f i) = p@cs") \napply(drule skolemize1) \napply clarify \napply(rename_tac p) \napply(erule_tac p=p in execs_drop_suffix0, assumption) \napply (blast dest:order_less_imp_le) \napply(fast intro: LeastI) \napply(erule thin_rl) \napply(erule_tac x = "LEAST j. fst (f j) = fst (f i)" in allE) \napply blast \napply(erule least_aux,assumption) \napply(fast intro: LeastI) \napply clarify \napply(drule not_less_Least) \napply blast \ndone \nlemma skolemize2: "\<forall>x.\<exists>y. P x y \<Longrightarrow> \<exists>f.\<forall>x. P x (f x)" \napply(rule_tac x = "\<lambda>x. SOME y. P x y" in exI) \napply(fast intro:someI2) \ndone \nlemma inf_cases: "inf (c#cs) s \<Longrightarrow> inf [c] s \<or> (\<exists>t. s -c\<rightarrow> t \<and> inf cs t)" \napply(unfold inf_def) \napply (clarsimp del: disjCI) \napply(case_tac "\<exists>i. fst(f i) = cs") \napply(rule disjI2) \napply(drule least_lem, assumption, assumption) \napply clarify \napply(drule exec1s_impl_exec) \napply(case_tac "f k") \napply simp \napply (rule exI, rule conjI, assumption) \napply(rule_tac x="\<lambda>i. f(i+k)" in exI) \napply (clarsimp) \napply(rule disjI1) \napply simp \napply(subgoal_tac "\<forall>i. \<exists>p. p \<noteq> [] \<and> fst(f i) = p@cs") \napply(drule skolemize2) \napply clarify \napply(rename_tac p) \napply(rule_tac x = "\<lambda>i. (p i, snd(f i))" in exI) \napply(rule conjI) \napply(erule_tac x = 0 in allE, erule conjE) \napply simp \napply clarify \napply(erule_tac x = i in allE) \napply(erule_tac x = i in allE) \napply(frule_tac x = i in spec) \napply(erule_tac x = "Suc i" in allE) \napply(case_tac "f i") \napply(case_tac "f(Suc i)") \napply clarsimp \napply(blast intro:exec1_drop_suffix) \napply(clarify) \napply(induct_tac i) \napply force \napply clarsimp \napply(case_tac p) \napply blast \napply(erule_tac x=n in allE) \napply(erule_tac x="Suc n" in allE) \napply(case_tac "f n") \napply(case_tac "f(Suc n)") \napply clarsimp \napply(drule exec1_only1) \napply clarsimp \ndone \nlemma termi_impl_not_inf: "c \<down> s \<Longrightarrow> \<not> inf [c] s" \napply(erule termi.induct) \n(*Do*) \napply clarify \n(*Semi*) \napply(blast dest:inf_cases) \n(* Cond *) \napply clarsimp \napply clarsimp \n(*While*) \napply clarsimp \napply(fastforce dest:inf_cases) \n(*Call*) \napply blast \n(*Local*) \napply(blast dest:inf_cases) \ndone \nlemma termi_impl_no_inf_chain: "c\<down>s \<Longrightarrow> \<not>(\<exists>f. f 0 = ([c],s) \<and> (\<forall>i::nat. (f i, f(i+1)) : exec1^+))" \napply(subgoal_tac "wf({(y,x). ([c],s) \<rightarrow>\<^sup>* x & x \<rightarrow> y}^+)") \napply(simp only:wf_iff_no_infinite_down_chain) \napply(erule contrapos_nn) \napply clarify \napply(subgoal_tac "\<forall>i. ([c], s) \<rightarrow>\<^sup>* f i") \nprefer 2 \napply(rule allI) \napply(induct_tac i) \napply simp \napply simp \napply(blast intro: trancl_into_rtrancl rtrancl_trans) \napply(rule_tac x=f in exI) \napply clarify \napply(drule_tac x=i in spec) \napply(subst lem) \napply(blast intro: trancl_into_rtrancl rtrancl_trans) \napply clarsimp \napply(rule wf_trancl) \napply(simp only:wf_iff_no_infinite_down_chain) \napply(clarify) \napply simp \napply(drule renumber) \napply(fold inf_def) \napply(simp add: termi_impl_not_inf) \ndone \nprimrec cseq :: "(nat \<Rightarrow> state) \<Rightarrow> nat \<Rightarrow> com list" where "cseq S 0 = []" | "cseq S (Suc i) = (SOME cs. ([body], S i) \<rightarrow>\<^sup>* (CALL # cs, S(i+1))) @ cseq S i" \nlemma wf_termi_call_steps: "wf termi_call_steps" \napply(unfold termi_call_steps_def) \napply(simp only:wf_iff_no_infinite_down_chain) \napply(clarify) \napply(rename_tac S) \napply simp \napply(subgoal_tac "\<exists>Cs. Cs 0 = [] & (\<forall>i. (body # Cs i,S i) \<rightarrow>\<^sup>* (CALL # Cs(i+1), S(i+1)))") \nprefer 2 \napply(rule_tac x = "cseq S" in exI) \napply clarsimp \napply(erule_tac x=i in allE) \napply(clarify) \napply(erule_tac P = "\<lambda>cs.([body],S i) \<rightarrow>\<^sup>* (CALL # cs, S(Suc i))" in someI2) \napply(fastforce dest:app_execs) \napply clarify \napply(subgoal_tac "\<forall>i. ((body # Cs i,S i), (body # Cs(i+1), S(i+1))) : exec1^+") \nprefer 2 \napply(blast intro:rtrancl_into_trancl1) \napply(subgoal_tac "\<exists>f. f 0 = ([body],S 0) \<and> (\<forall>i. (f i, f(i+1)) : exec1^+)") \nprefer 2 \napply(rule_tac x = "\<lambda>i.(body#Cs i,S i)" in exI) \napply blast \napply(blast dest:termi_impl_no_inf_chain) \ndone \nlemma CALL_lemma: "{(\<lambda>z s. (z=s \<and> body\<down>s) \<and> (s,t) \<in> termi_call_steps, CALL, \<lambda>z s. z -body\<rightarrow> s)} \<turnstile>\<^sub>t {\<lambda>z s. (z=s \<and> body\<down>t) \<and> (\<exists>cs. ([body],t) \<rightarrow>\<^sup>* (c#cs,s))} c {\<lambda>z s. z -c\<rightarrow> s}" \napply(induct_tac c) \n(*Do*) \napply (rule strengthen_pre[OF _ thoare.Do]) \napply(blast dest: execs_pres_termi) \n(*Semi*) \napply(rename_tac c1 c2) \napply(rule_tac Q = "\<lambda>z s. body\<down>t & (\<exists>cs. ([body], t) \<rightarrow>\<^sup>* (c2#cs,s)) & z -c1\<rightarrow>s & c2\<down>s" in thoare.Semi) \napply(erule thoare.Conseq) \napply(rule conjI) \napply clarsimp \napply(subgoal_tac "s -c1\<rightarrow> ta") \nprefer 2 \napply(blast intro: exec1.Semi exec_impl_execs rtrancl_trans) \napply(subgoal_tac "([body], t) \<rightarrow>\<^sup>* (c2 # cs, ta)") \nprefer 2 \napply(blast intro:exec1.Semi[THEN r_into_rtrancl] exec_impl_execs rtrancl_trans) \napply(subgoal_tac "([body], t) \<rightarrow>\<^sup>* (c2 # cs, ta)") \nprefer 2 \napply(blast intro: exec_impl_execs rtrancl_trans) \napply(blast intro:exec_impl_execs rtrancl_trans execs_pres_termi) \napply(fast intro: exec1.Semi rtrancl_trans) \napply(erule thoare.Conseq) \napply blast \n(*Call*) \nprefer 3 \napply(simp only:termi_call_steps_def) \napply(rule thoare.Conseq[OF thoare.Asm]) \napply(blast dest: execs_pres_termi) \n(*If*) \napply(rule thoare.If) \napply(erule thoare.Conseq) \napply simp \napply(blast intro: exec1.IfTrue rtrancl_trans) \napply(erule thoare.Conseq) \napply simp \napply(blast intro: exec1.IfFalse rtrancl_trans) \n(*Var*) \ndefer \napply simp \napply(rule thoare.Local) \napply(rule allI) \napply(erule thoare.Conseq) \napply (clarsimp) \napply(rule conjI) \napply (clarsimp) \napply(drule rtrancl_trans[OF _ r_into_rtrancl[OF exec1.Local]]) \napply(fast) \napply (clarsimp) \napply(drule rtrancl_trans[OF _ r_into_rtrancl[OF exec1.Local]]) \napply blast \napply(rename_tac b c) \napply(rule_tac P' = "\<lambda>z s. (z,s) \<in> ({(s,t). b s \<and> s -c\<rightarrow> t})^* \<and> body \<down> t \<and> (\<exists>cs. ([body], t) \<rightarrow>\<^sup>* ((WHILE b DO c) # cs, s))" in thoare.Conseq) \napply(rule_tac thoare.While[OF wf_termi]) \napply(rule allI) \napply(erule thoare.Conseq) \napply clarsimp \napply(rule conjI) \napply clarsimp \napply(rule conjI) \napply(blast intro: rtrancl_trans exec1.WhileTrue) \napply(rule conjI) \napply(rule exI, rule rtrancl_trans, assumption) \napply(blast intro: exec1.WhileTrue exec_impl_execs rtrancl_trans) \napply(rule conjI) \napply(blast intro:execs_pres_termi) \napply(blast intro: exec1.WhileTrue exec_impl_execs rtrancl_trans) \napply(blast intro: exec1.WhileTrue exec_impl_execs rtrancl_trans) \napply(rule conjI) \napply clarsimp \napply(erule_tac x = s in allE) \napply clarsimp \napply(erule impE) \napply blast \napply clarify \napply(erule_tac a=s in converse_rtrancl_induct) \napply simp \napply(fast elim:exec.WhileTrue) \napply(fast intro: rtrancl_refl) \ndone \nlemma CALL_cor: "{(\<lambda>z s. (z=s \<and> body\<down>s) \<and> (s,t) \<in> termi_call_steps, CALL, \<lambda>z s. z -body\<rightarrow> s)} \<turnstile>\<^sub>t {\<lambda>z s. (z=s \<and> body\<down>s) \<and> s = t} body {\<lambda>z s. z -body\<rightarrow> s}" \napply(rule strengthen_pre[OF _ CALL_lemma]) \napply blast \ndone \nlemma MGT_CALL: "{} \<turnstile>\<^sub>t MGT\<^sub>t CALL" \napply(simp add: MGT\<^sub>t_def) \napply(blast intro:thoare.Call wf_termi_call_steps CALL_cor) \ndone [/INST]\napply(erule MGT_implies_complete[OF MGT_lemma[OF MGT_CALL]]) \ndone \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma strengthen_pre: "\<lbrakk> \<forall>z s. P' z s \<longrightarrow> P z s; C\<turnstile> {P}c{Q} \<rbrakk> \<Longrightarrow> C\<turnstile> {P'}c{Q}" \nby(rule hoare.Conseq, assumption, blast) \nlemmas valid_defs = valid_def valids_def cvalid_def nvalid_def nvalids_def cnvalid_def \ntheorem hoare_sound: "C \<turnstile> {P}c{Q} \<Longrightarrow> C \<Turnstile> {P}c{Q}" \ntxt\<open>\noindent requires a generalization: @{prop"\<forall>n. C \<Turnstile>n {P}c{Q}"} is proved instead, from which the actual theorem follows directly via lemma @{thm[source]exec_iff_execn} in \S\ref{sec:proc1-lang}. The generalization is proved by induction on @{term c}. The reason for the generalization is that soundness of the @{term CALL} rule is proved by induction on the maximal call depth, i.e.\ @{term n}.\<close> \napply(subgoal_tac "\<forall>n. C \<Turnstile>n {P}c{Q}") \napply(unfold valid_defs exec_iff_execn) \napply fast \napply(erule hoare.induct) \napply simp \napply fast \napply simp \napply clarify \napply(drule while_rule) \nprefer 3 \napply (assumption, assumption) \napply fast \napply fast \nprefer 2 \napply simp \napply(rule allI, rule impI) \napply(induct_tac n) \napply blast \napply clarify \napply (simp(no_asm_use)) \napply blast \napply auto \ndone \ntext\<open> The completeness proof employs the notion of a \emph{most general triple} (or \emph{most general formula}):\<close> \ndefinition MGT :: "com \<Rightarrow> state assn \<times> com \<times> state assn" where "MGT c = (\<lambda>z s. z = s, c, \<lambda>z t. z -c\<rightarrow> t)" \ndeclare MGT_def[simp] \ntext\<open>\noindent Note that the type of @{term z} has been identified with @{typ state}. This means that for every state variable there is an auxiliary variable, which is simply there to record the value of the program variables before execution of a command. This is exactly what, for example, VDM offers by allowing you to refer to the pre-value of a variable in a postcondition. The intuition behind @{term"MGT c"} is that it completely describes the operational behaviour of @{term c}. It is easy to see that, in the presence of the new consequence rule, \mbox{@{prop"{} \<turnstile> MGT c"}} implies completeness:\<close> \nlemma MGT_implies_complete: "{} \<turnstile> MGT c \<Longrightarrow> {} \<Turnstile> {P}c{Q} \<Longrightarrow> {} \<turnstile> {P}c{Q::state assn}" \napply(simp add: MGT_def) \napply (erule hoare.Conseq) \napply(simp add: valid_defs) \ndone \ntext\<open>In order to discharge @{prop"{} \<turnstile> MGT c"} one proves\<close> \nlemma MGT_lemma: "C \<turnstile> MGT CALL \<Longrightarrow> C \<turnstile> MGT c" \napply (simp) \napply(induct_tac c) \napply (rule strengthen_pre[OF _ hoare.Do]) \napply blast \napply(blast intro:hoare.Semi hoare.Conseq) \napply(rule hoare.If) \napply(erule hoare.Conseq) \napply simp \napply(erule hoare.Conseq) \napply simp \nprefer 2 \napply simp \napply(rename_tac b c) \napply(rule hoare.Conseq) \napply(rule_tac P = "\<lambda>z s. (z,s) \<in> ({(s,t). b s \<and> s -c\<rightarrow> t})^*" in hoare.While) \napply(erule hoare.Conseq) \napply(blast intro:rtrancl_into_rtrancl) \napply clarsimp \napply(rename_tac s t) \napply(erule_tac x = s in allE) \napply clarsimp \napply(erule converse_rtrancl_induct) \napply simp \napply(fast elim:exec.WhileTrue) \napply(fastforce intro: hoare.Local elim!: hoare.Conseq) \ndone \ntext\<open>\noindent The proof is by induction on @{term c}. In the @{term While}-case it is easy to show that @{term"\<lambda>z t. (z,t) \<in> ({(s,t). b s \<and> s -c\<rightarrow> t})^*"} is invariant. The precondition \mbox{@{term[source]"\<lambda>z s. z=s"}} establishes the invariant and a reflexive transitive closure induction shows that the invariant conjoined with @{prop"\<not>b t"} implies the postcondition \mbox{@{term"\<lambda>z t. z -WHILE b DO c\<rightarrow> t"}}. The remaining cases are trivial. Using the @{thm[source]MGT_lemma} (together with the \<open>CALL\<close> and the assumption rule) one can easily derive\<close> \nlemma MGT_CALL: "{} \<turnstile> MGT CALL" \napply(simp add: MGT_def) \napply (rule hoare.Call) \napply (rule hoare.Conseq[OF MGT_lemma[simplified], OF hoare.Asm]) \napply (fast intro:exec.intros) \ndone \ntext\<open>\noindent Using the @{thm[source]MGT_lemma} once more we obtain @{prop"{} \<turnstile> MGT c"} and thus by @{thm[source]MGT_implies_complete} completeness.\<close> [/INST]\napply(erule MGT_implies_complete[OF MGT_lemma[OF MGT_CALL]]) \ndone \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma [iff]: "(s -Do f\<rightarrow> t) = (t \<in> f s)" \nby(auto elim: exec.cases intro:exec.intros) \nlemma [iff]: "(s -c;d\<rightarrow> u) = (\<exists>t. s -c\<rightarrow> t \<and> t -d\<rightarrow> u)" \nby(auto elim: exec.cases intro:exec.intros) \nlemma [iff]: "(s -IF b THEN c ELSE d\<rightarrow> t) = (s -if b s then c else d\<rightarrow> t)" \napply(rule iffI) \napply(auto elim: exec.cases intro:exec.intros) \napply(auto intro:exec.intros split:if_split_asm) \ndone \nlemma unfold_while: "(s -WHILE b DO c\<rightarrow> u) = (s -IF b THEN c;WHILE b DO c ELSE Do(\<lambda>s. {s})\<rightarrow> u)" \nby(auto elim: exec.cases intro:exec.intros split:if_split_asm) \nlemma [iff]: "(s -CALL\<rightarrow> t) = (s -body\<rightarrow> t)" \nby(blast elim: exec.cases intro:exec.intros) \nlemma [iff]: "(s -LOCAL f; c; g\<rightarrow> u) = (\<exists>t. f s -c\<rightarrow> t \<and> u = g s t)" \nby(fastforce elim: exec.cases intro:exec.intros) \nlemma [simp]: "\<not>b s \<Longrightarrow> s -WHILE b DO c\<rightarrow> s" \nby(fast intro:exec.intros) \nlemma WhileI: "\<lbrakk>b s; s -c\<rightarrow> t; t -WHILE b DO c\<rightarrow> u\<rbrakk> \<Longrightarrow> s -WHILE b DO c\<rightarrow> u" \nby(fastforce elim:exec.WhileTrue) \n(*>*) \ntext\<open>This semantics turns out not to be fine-grained enough. The soundness proof for the Hoare logic below proceeds by induction on the call depth during execution. To make this work we define a second semantics \mbox{\<open>s -c-n\<rightarrow> t\<close>} which expresses that the execution uses at most @{term n} nested procedure invocations, where @{term n} is a natural number. The rules are straightforward: @{term n} is just passed around, except for procedure calls, where it is decremented:\<close> \ninductive execn :: "state \<Rightarrow> com \<Rightarrow> nat \<Rightarrow> state \<Rightarrow> bool" ("_/ -_-_\<rightarrow>/ _" [50,0,0,50] 50) where "t \<in> f s \<Longrightarrow> s -Do f-n\<rightarrow> t" | "\<lbrakk> s0 -c1-n\<rightarrow> s1; s1 -c2-n\<rightarrow> s2 \<rbrakk> \<Longrightarrow> s0 -c1;c2-n\<rightarrow> s2" | "\<lbrakk> b s; s -c1-n\<rightarrow> t \<rbrakk> \<Longrightarrow> s -IF b THEN c1 ELSE c2-n\<rightarrow> t" | "\<lbrakk> \<not>b s; s -c2-n\<rightarrow> t \<rbrakk> \<Longrightarrow> s -IF b THEN c1 ELSE c2-n\<rightarrow> t" | (*<*)WhileFalse:(*>*)"\<not>b s \<Longrightarrow> s -WHILE b DO c-n\<rightarrow> s" | (*<*)WhileTrue:(*>*)"\<lbrakk>b s; s -c-n\<rightarrow> t; t -WHILE b DO c-n\<rightarrow> u\<rbrakk> \<Longrightarrow> s -WHILE b DO c-n\<rightarrow> u" | "s -body-n\<rightarrow> t \<Longrightarrow> s -CALL-Suc n\<rightarrow> t" | "f s -c-n\<rightarrow> t \<Longrightarrow> s -LOCAL f; c; g-n\<rightarrow> g s t" \nlemma [iff]: "(s -Do f-n\<rightarrow> t) = (t \<in> f s)" \nby(auto elim: execn.cases intro:execn.intros) \nlemma [iff]: "(s -c1;c2-n\<rightarrow> u) = (\<exists>t. s -c1-n\<rightarrow> t \<and> t -c2-n\<rightarrow> u)" \nby(best elim: execn.cases intro:execn.intros) \nlemma [iff]: "(s -IF b THEN c ELSE d-n\<rightarrow> t) = (s -if b s then c else d-n\<rightarrow> t)" \napply auto \napply(blast elim: execn.cases intro:execn.intros)+ \ndone \nlemma [iff]: "(s -CALL- 0\<rightarrow> t) = False" \nby(blast elim: execn.cases intro:execn.intros) \nlemma [iff]: "(s -CALL-Suc n\<rightarrow> t) = (s -body-n\<rightarrow> t)" \nby(blast elim: execn.cases intro:execn.intros) \nlemma [iff]: "(s -LOCAL f; c; g-n\<rightarrow> u) = (\<exists>t. f s -c-n\<rightarrow> t \<and> u = g s t)" \nby(auto elim: execn.cases intro:execn.intros) \ntext\<open>\noindent By induction on @{prop"s -c-m\<rightarrow> t"} we show monotonicity w.r.t.\ the call depth:\<close> \nlemma exec_mono[rule_format]: "s -c-m\<rightarrow> t \<Longrightarrow> \<forall>n. m \<le> n \<longrightarrow> s -c-n\<rightarrow> t" \napply(erule execn.induct) \napply(blast) \napply(blast) \napply(simp) \napply(simp) \napply(simp add:execn.intros) \napply(blast intro:execn.intros) \napply(clarify) \napply(rename_tac m) \napply(case_tac m) \napply simp \napply simp \napply blast \ndone \ntext\<open>\noindent With the help of this lemma we prove the expected relationship between the two semantics:\<close> \nlemma exec_iff_execn: "(s -c\<rightarrow> t) = (\<exists>n. s -c-n\<rightarrow> t)" \napply(rule iffI) \napply(erule exec.induct) \napply blast \napply clarify \napply(rename_tac m n) \napply(rule_tac x = "max m n" in exI) \napply(fastforce intro:exec.intros exec_mono simp add:max_def) \napply fastforce \napply fastforce \napply(blast intro:execn.intros) \napply clarify \napply(rename_tac m n) \napply(rule_tac x = "max m n" in exI) \napply(fastforce elim:execn.WhileTrue exec_mono simp add:max_def) \napply blast \napply blast \napply(erule exE, erule execn.induct) \napply blast \napply blast \napply fastforce \napply fastforce \napply(erule exec.WhileFalse) \napply(blast intro: exec.intros) \napply blast \napply blast \ndone \nlemma while_lemma[rule_format]: "s -w-n\<rightarrow> t \<Longrightarrow> \<forall>b c. w = WHILE b DO c \<and> P s \<and> (\<forall>s s'. P s \<and> b s \<and> s -c-n\<rightarrow> s' \<longrightarrow> P s') \<longrightarrow> P t \<and> \<not>b t" \napply(erule execn.induct) \napply clarify+ \ndefer \napply clarify+ \napply(subgoal_tac "P t") \napply blast \napply blast \ndone [/INST]\napply(drule while_lemma) \nprefer 2 \napply assumption \napply blast \ndone \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \nlemma [iff]: "(Do f \<down> s) = (f s \<noteq> {})" \napply(rule iffI) \nprefer 2 \napply(best intro:termi.intros) \napply(erule termi.cases) \napply blast+ \ndone \nlemma [iff]: "((c1;c2) \<down> s0) = (c1 \<down> s0 \<and> (\<forall>s1. s0 -c1\<rightarrow> s1 \<longrightarrow> c2 \<down> s1))" \napply(rule iffI) \nprefer 2 \napply(best intro:termi.intros) \napply(erule termi.cases) \napply blast+ \ndone \nlemma [iff]: "(IF b THEN c1 ELSE c2 \<down> s) = ((if b s then c1 else c2) \<down> s)" \napply simp \napply(rule conjI) \napply(rule impI) \napply(rule iffI) \nprefer 2 \napply(blast intro:termi.intros) \napply(erule termi.cases) \napply blast+ \napply(rule impI) \napply(rule iffI) \nprefer 2 \napply(blast intro:termi.intros) \napply(erule termi.cases) \napply blast+ \ndone \nlemma [iff]: "(CALL \<down> s) = (body \<down> s)" \nby(fast elim: termi.cases intro:termi.intros) \nlemma [iff]: "(LOCAL f;c;g \<down> s) = (c \<down> f s)" \nby(fast elim: termi.cases intro:termi.intros) \nlemma termi_while_lemma[rule_format]: "w\<down>fk \<Longrightarrow> (\<forall>k b c. fk = f k \<and> w = WHILE b DO c \<and> (\<forall>i. f i -c\<rightarrow> f(Suc i)) \<longrightarrow> (\<exists>i. \<not>b(f i)))" \napply(erule termi.induct) \napply simp_all \napply blast \napply blast \ndone \nlemma termi_while: "\<lbrakk> (WHILE b DO c) \<down> f k; \<forall>i. f i -c\<rightarrow> f(Suc i) \<rbrakk> \<Longrightarrow> \<exists>i. \<not>b(f i)" \nby(blast intro:termi_while_lemma) [/INST]\napply(subst wf_iff_no_infinite_down_chain) \napply(rule notI) \napply clarsimp \napply(insert termi_while) \napply blast \ndone \nend
An user requests an Isabelle/HOL proof completion to an AI Assistant proof generator for a current problem, lemma or theorem.[INST]Infer a proof for the following Isabelle/HOL theorem statement/s: \ntheorem "\<turnstile>\<^sub>t {P}c{Q} \<Longrightarrow> \<Turnstile>\<^sub>t {P}c{Q}" \napply(unfold hoare_tvalid_def hoare_valid_def) \napply(erule thoare.induct) \napply blast \napply blast \napply clarsimp \ndefer \napply blast \napply(rule conjI) \napply clarify \napply(erule allE) \napply clarify \napply(erule allE, erule allE, erule impE, erule asm_rl) \napply simp \napply(erule mp) \napply(simp) \napply blast \napply(rule conjI) \napply(rule allI) \napply(erule wf_induct) \napply clarify \napply(drule unfold_while[THEN iffD1]) \napply (simp split: if_split_asm) \napply blast \napply(rule allI) \napply(erule wf_induct) \napply clarify \napply(case_tac "b x") \napply (blast intro: termi.WhileTrue) \napply (erule termi.WhileFalse) \ndone \n(*>*) \ntext\<open>\noindent In the @{term While}-case we perform a local proof by wellfounded induction over the given relation @{term r}. The completeness proof proceeds along the same lines as the one for partial correctness. First we have to strengthen our notion of weakest precondition to take termination into account:\<close> \ndefinition wpt :: "com \<Rightarrow> assn \<Rightarrow> assn" ("wp\<^sub>t") where "wp\<^sub>t c Q = (\<lambda>s. wp c Q s \<and> c\<down>s)" \nlemmas wp_defs = wp_def wpt_def \nlemma [simp]: "wp\<^sub>t (Do f) Q = (\<lambda>s. (\<forall>t \<in> f s. Q t) \<and> f s \<noteq> {})" \nby(simp add: wpt_def) \nlemma [simp]: "wp\<^sub>t (c\<^sub>1;c\<^sub>2) R = wp\<^sub>t c\<^sub>1 (wp\<^sub>t c\<^sub>2 R)" \napply(unfold wp_defs) \napply(rule ext) \napply blast \ndone \nlemma [simp]: "wp\<^sub>t (IF b THEN c\<^sub>1 ELSE c\<^sub>2) Q = (\<lambda>s. wp\<^sub>t (if b s then c\<^sub>1 else c\<^sub>2) Q s)" \napply(unfold wp_defs) \napply(rule ext) \napply auto \ndone \nlemma [simp]: "wp\<^sub>t (LOCAL f;c;g) Q = (\<lambda>s. wp\<^sub>t c (Q o (g s)) (f s))" \napply(unfold wp_defs) \napply(rule ext) \napply auto \ndone \nlemma strengthen_pre: "\<lbrakk> \<forall>s. P' s \<longrightarrow> P s; \<turnstile>\<^sub>t {P}c{Q} \<rbrakk> \<Longrightarrow> \<turnstile>\<^sub>t {P'}c{Q}" \nby(erule thoare.Conseq, assumption, blast) \nlemma weaken_post: "\<lbrakk> \<turnstile>\<^sub>t {P}c{Q}; \<forall>s. Q s \<longrightarrow> Q' s \<rbrakk> \<Longrightarrow> \<turnstile>\<^sub>t {P}c{Q'}" \napply(rule thoare.Conseq) \napply(fast, assumption, assumption) \ndone \ninductive_cases [elim!]: "WHILE b DO c \<down> s" \nlemma wp_is_pre[rule_format]: "\<turnstile>\<^sub>t {wp\<^sub>t c Q} c {Q}" \napply (induct c arbitrary: Q) \napply simp_all \napply(blast intro:thoare.Do thoare.Conseq) \napply(blast intro:thoare.Semi thoare.Conseq) \napply(blast intro:thoare.If thoare.Conseq) \ndefer \napply(fastforce intro!: thoare.Local) \napply(rename_tac b c Q) \napply(rule weaken_post) \napply(rule_tac b=b and c=c in thoare.While) \napply(rule_tac b=b and c=c in wf_termi) \ndefer \napply (simp add:wp_defs unfold_while) \napply(rule allI) \napply(rule strengthen_pre) \nprefer 2 \napply fast \napply(clarsimp simp add: wp_defs) \napply(blast intro:exec.intros) \ndone \ntext\<open>\noindent The @{term While}-case is interesting because we now have to furnish a suitable wellfounded relation. Of course the execution of the loop body directly yields the required relation. The actual completeness theorem follows directly, in the same manner as for partial correctness.\<close> [/INST]\napply (rule strengthen_pre[OF _ wp_is_pre]) \napply(unfold hoare_tvalid_def hoare_valid_def wp_defs) \napply blast \ndone \nend

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
0
Add dataset card