(* Title: OAWN_Convert.thy License: BSD 2-Clause. See LICENSE. Author: Timothy Bourke *) section "Transfer standard invariants into open invariants" theory OAWN_Convert imports AWN_SOS_Labels AWN_Invariants OAWN_SOS OAWN_Invariants begin definition initiali :: "'i \ (('i \ 'g) \ 'l) set \ ('g \ 'l) set \ bool" where "initiali i OI CI \ ({(\ i, p)|\ p. (\, p) \ OI} = CI)" lemma initialiI [intro]: assumes OICI: "\\ p. (\, p) \ OI \ (\ i, p) \ CI" and CIOI: "\\ p. (\, p) \ CI \ \\. \ = \ i \ (\, p) \ OI" shows "initiali i OI CI" unfolding initiali_def by (intro set_eqI iffI) (auto elim!: OICI CIOI) lemma open_from_initialiD [dest]: assumes "initiali i OI CI" and "(\, p) \ OI" shows "\\. \ i = \ \ (\, p) \ CI" using assms unfolding initiali_def by auto lemma closed_from_initialiD [dest]: assumes "initiali i OI CI" and "(\, p) \ CI" shows "\\. \ i = \ \ (\, p) \ OI" using assms unfolding initiali_def by auto definition seql :: "'i \ (('s \ 'l) \ bool) \ (('i \ 's) \ 'l) \ bool" where "seql i P \ (\(\, p). P (\ i, p))" lemma seqlI [intro]: "P (fst s i, snd s) \ seql i P s" by (clarsimp simp: seql_def) lemma same_seql [elim]: assumes "\j\{i}. \' j = \ j" and "seql i P (\', s)" shows "seql i P (\, s)" using assms unfolding seql_def by (clarsimp) lemma seqlsimp: "seql i P (\, p) = P (\ i, p)" unfolding seql_def by simp lemma other_steps_resp_local [intro!, simp]: "other_steps (other A I) I" by (clarsimp elim!: otherE) lemma seql_onl_swap: "seql i (onl \ P) = onl \ (seql i P)" unfolding seql_def onl_def by simp lemma oseqp_sos_resp_local_steps [intro!, simp]: fixes \ :: "'p \ ('s, 'm, 'p, 'l) seqp" shows "local_steps (oseqp_sos \ i) {i}" proof fix \ \' \ \' :: "nat \ 's" and s a s' assume tr: "((\, s), a, \', s') \ oseqp_sos \ i" and "\j\{i}. \ j = \ j" thus "\\'. (\j\{i}. \' j = \' j) \ ((\, s), a, (\', s')) \ oseqp_sos \ i" proof induction fix \ \' l ms p assume "\' i = \ i" and "\j\{i}. \ j = \ j" hence "((\, {l}broadcast(ms).p), broadcast (ms (\ i)), (\', p)) \ oseqp_sos \ i" by (metis obroadcastT singleton_iff) with \\j\{i}. \ j = \ j\ show "\\'. (\j\{i}. \' j = \' j) \ ((\, {l}broadcast(ms).p), broadcast (ms (\ i)), (\', p)) \ oseqp_sos \ i" by blast next fix \ \' :: "nat \ 's" and fmsg :: "'m \ 's \ 's" and msg l p assume *: "\' i = fmsg msg (\ i)" and **: "\j\{i}. \ j = \ j" hence "\j\{i}. (\(i := fmsg msg (\ i))) j = \' j" by clarsimp moreover from * ** have "((\, {l}receive(fmsg).p), receive msg, (\(i := fmsg msg (\ i)), p)) \ oseqp_sos \ i" by (metis fun_upd_same oreceiveT) ultimately show "\\'. (\j\{i}. \' j = \' j) \ ((\, {l}receive(fmsg).p), receive msg, (\', p)) \ oseqp_sos \ i" by blast next fix \' \ l p and fas :: "'s \ 's" assume *: "\' i = fas (\ i)" and **: "\j\{i}. \ j = \ j" hence "\j\{i}. (\(i := fas (\ i))) j = \' j" by clarsimp moreover from * ** have "((\, {l}\fas\ p), \, (\(i := fas (\ i)), p)) \ oseqp_sos \ i" by (metis fun_upd_same oassignT) ultimately show "\\'. (\j\{i}. \' j = \' j) \ ((\, {l}\fas\ p), \, (\', p)) \ oseqp_sos \ i" by blast next fix g :: "'s \ 's set" and \ \' l p assume *: "\' i \ g (\ i)" and **: "\j\{i}. \ j = \ j" hence "\j\{i}. (SOME \'. \' i = \' i) j = \' j" by simp (metis (lifting, full_types) some_eq_ex) moreover with * ** have "((\, {l}\g\ p), \, (SOME \'. \' i = \' i, p)) \ oseqp_sos \ i" by simp (metis oguardT step_seq_tau) ultimately show "\\'. (\j\{i}. \' j = \' j) \ ((\, {l}\g\ p), \, (\', p)) \ oseqp_sos \ i" by blast next fix \ pn a \' p' assume "((\, \ pn), a, (\', p')) \ oseqp_sos \ i" and IH: "\j\{i}. \ j = \ j \ \\'. (\j\{i}. \' j = \' j) \ ((\, \ pn), a, (\', p')) \ oseqp_sos \ i" and "\j\{i}. \ j = \ j" then obtain \' where "\j\{i}. \' j = \' j" and "((\, \ pn), a, (\', p')) \ oseqp_sos \ i" by blast thus "\\'. (\j\{i}. \' j = \' j) \ ((\, call(pn)), a, (\', p')) \ oseqp_sos \ i" by blast next fix \ p a \' p' q assume "((\, p), a, (\', p')) \ oseqp_sos \ i" and "\j\{i}. \ j = \ j \ \\'. (\j\{i}. \' j = \' j) \ ((\, p), a, (\', p')) \ oseqp_sos \ i" and "\j\{i}. \ j = \ j" then obtain \' where "\j\{i}. \' j = \' j" and "((\, p), a, (\', p')) \ oseqp_sos \ i" by blast thus "\\'. (\j\{i}. \' j = \' j) \ ((\, p \ q), a, (\', p')) \ oseqp_sos \ i" by blast next fix \ p a \' q q' assume "((\, q), a, (\', q')) \ oseqp_sos \ i" and "\j\{i}. \ j = \ j \ \\'. (\j\{i}. \' j = \' j) \ ((\, q), a, (\', q')) \ oseqp_sos \ i" and "\j\{i}. \ j = \ j" then obtain \' where "\j\{i}. \' j = \' j" and "((\, q), a, (\', q')) \ oseqp_sos \ i" by blast thus "\\'. (\j\{i}. \' j = \' j) \ ((\, p \ q), a, (\', q')) \ oseqp_sos \ i" by blast qed (simp_all, (metis ogroupcastT ounicastT onotunicastT osendT odeliverT)+) qed lemma oseqp_sos_subreachable [intro!, simp]: assumes "trans OA = oseqp_sos \ i" shows "subreachable OA (other ANY {i}) {i}" by rule (clarsimp simp add: assms(1))+ lemma oseq_step_is_seq_step: fixes \ :: "ip \ 's" assumes "((\, p), a :: 'm seq_action, (\', p')) \ oseqp_sos \ i" and "\ i = \" shows "\\'. \' i = \' \ ((\, p), a, (\', p')) \ seqp_sos \" using assms proof induction fix \ \' l ms p assume "\' i = \ i" and "\ i = \" hence "\' i = \" by simp have "((\, {l}broadcast(ms).p), broadcast (ms \), (\, p)) \ seqp_sos \" by auto with \\ i = \\ and \\' i = \\ show "\\'. \' i = \' \ ((\, {l}broadcast(ms).p), broadcast (ms (\ i)), (\', p)) \ seqp_sos \" by clarsimp next fix fmsg :: "'m \ 's \ 's" and msg :: 'm and \' \ l p assume "\' i = fmsg msg (\ i)" and "\ i = \" have "((\, {l}receive(fmsg).p), receive msg, (fmsg msg \, p)) \ seqp_sos \" by auto with \\' i = fmsg msg (\ i)\ and \\ i = \\ show "\\'. \' i = \' \ ((\, {l}receive(fmsg).p), receive msg, (\', p)) \ seqp_sos \" by clarsimp qed (simp_all, (metis assignT choiceT1 choiceT2 groupcastT guardT callT unicastT notunicastT sendT deliverT step_seq_tau)+) lemma reachable_oseq_seqp_sos: assumes "(\, p) \ reachable OA I" and "initiali i (init OA) (init A)" and spo: "trans OA = oseqp_sos \ i" and sp: "trans A = seqp_sos \" shows "\\. \ i = \ \ (\, p) \ reachable A I" using assms(1) proof (induction rule: reachable_pair_induct) fix \ p assume "(\, p) \ init OA" with \initiali i (init OA) (init A)\ obtain \ where "\ i = \" and "(\, p) \ init A" by auto from \(\, p) \ init A\ have "(\, p) \ reachable A I" .. with \\ i = \\ show "\\. \ i = \ \ (\, p) \ reachable A I" by auto next fix \ p \' p' a assume "(\, p) \ reachable OA I" and IH: "\\. \ i = \ \ (\, p) \ reachable A I" and otr: "((\, p), a, (\', p')) \ trans OA" and "I a" from IH obtain \ where "\ i = \" and cr: "(\, p) \ reachable A I" by clarsimp from otr and spo have "((\, p), a, (\', p')) \ oseqp_sos \ i" by simp with \\ i = \\ obtain \' where "\' i = \'" and "((\, p), a, (\', p')) \ seqp_sos \" by (auto dest!: oseq_step_is_seq_step) from this(2) and sp have ctr: "((\, p), a, (\', p')) \ trans A" by simp from \(\, p) \ reachable A I\ and ctr and \I a\ have "(\', p') \ reachable A I" .. with \\' i = \'\ show "\\. \' i = \ \ (\, p') \ reachable A I" by blast qed lemma reachable_oseq_seqp_sos': assumes "s \ reachable OA I" and "initiali i (init OA) (init A)" and "trans OA = oseqp_sos \ i" and "trans A = seqp_sos \" shows "\\. (fst s) i = \ \ (\, snd s) \ reachable A I" using assms by - (cases s, auto dest: reachable_oseq_seqp_sos) text \ Any invariant shown in the (simpler) closed semantics can be transferred to an invariant in the open semantics. \ theorem open_seq_invariant [intro]: assumes "A \ (I \) P" and "initiali i (init OA) (init A)" and spo: "trans OA = oseqp_sos \ i" and sp: "trans A = seqp_sos \" shows "OA \ (act I, other ANY {i} \) (seql i P)" proof - have "OA \ (I \) (seql i P)" proof (rule invariant_arbitraryI) fix s assume "s \ reachable OA I" with \initiali i (init OA) (init A)\ obtain \ where "(fst s) i = \" and "(\, snd s) \ reachable A I" by (auto dest: reachable_oseq_seqp_sos' [OF _ _ spo sp]) with \A \ (I \) P\ have "P (\, snd s)" by auto with \(fst s) i = \\ show "seql i P s" by auto qed moreover from spo have "subreachable OA (other ANY {i}) {i}" .. ultimately show ?thesis proof (rule open_closed_invariant) fix \ \' s assume "\j\{i}. \' j = \ j" and "seql i P (\', s)" thus "seql i P (\, s)" .. qed qed definition seqll :: "'i \ ((('s \ 'l) \ 'a \ ('s \ 'l)) \ bool) \ ((('i \ 's) \ 'l) \ 'a \ (('i \ 's) \ 'l)) \ bool" where "seqll i P \ (\((\, p), a, (\', p')). P ((\ i, p), a, (\' i, p')))" lemma same_seqll [elim]: assumes "\j\{i}. \\<^sub>1' j = \\<^sub>1 j" and "\j\{i}. \\<^sub>2' j = \\<^sub>2 j" and "seqll i P ((\\<^sub>1', s), a, (\\<^sub>2', s'))" shows "seqll i P ((\\<^sub>1, s), a, (\\<^sub>2, s'))" using assms unfolding seqll_def by (clarsimp) lemma seqllI [intro!]: assumes "P ((\ i, p), a, (\' i, p'))" shows "seqll i P ((\, p), a, (\', p'))" using assms unfolding seqll_def by simp lemma seqllD [dest]: assumes "seqll i P ((\, p), a, (\', p'))" shows "P ((\ i, p), a, (\' i, p'))" using assms unfolding seqll_def by simp lemma seqllsimp: "seqll i P ((\, p), a, (\', p')) = P ((\ i, p), a, (\' i, p'))" unfolding seqll_def by simp lemma seqll_onll_swap: "seqll i (onll \ P) = onll \ (seqll i P)" unfolding seqll_def onll_def by simp theorem open_seq_step_invariant [intro]: assumes "A \\<^sub>A (I \) P" and "initiali i (init OA) (init A)" and spo: "trans OA = oseqp_sos \ i" and sp: "trans A = seqp_sos \" shows "OA \\<^sub>A (act I, other ANY {i} \) (seqll i P)" proof - have "OA \\<^sub>A (I \) (seqll i P)" proof (rule step_invariant_arbitraryI) fix \ p a \' p' assume or: "(\, p) \ reachable OA I" and otr: "((\, p), a, (\', p')) \ trans OA" and "I a" from or \initiali i (init OA) (init A)\ spo sp obtain \ where "\ i = \" and cr: "(\, p) \ reachable A I" by - (drule(3) reachable_oseq_seqp_sos', auto) from otr and spo have "((\, p), a, (\', p')) \ oseqp_sos \ i" by simp with \\ i = \\ obtain \' where "\' i = \'" and ctr: "((\, p), a, (\', p')) \ seqp_sos \" by (auto dest!: oseq_step_is_seq_step) with sp have "((\, p), a, (\', p')) \ trans A" by simp with \A \\<^sub>A (I \) P\ cr have "P ((\, p), a, (\', p'))" using \I a\ .. with \\ i = \\ and \\' i = \'\ have "P ((\ i, p), a, (\' i, p'))" by simp thus "seqll i P ((\, p), a, (\', p'))" .. qed moreover from spo have "local_steps (trans OA) {i}" by simp moreover have "other_steps (other ANY {i}) {i}" .. ultimately show ?thesis proof (rule open_closed_step_invariant) fix \ \ a \' \' s s' assume "\j\{i}. \ j = \ j" and "\j\{i}. \' j = \' j" and "seqll i P ((\, s), a, (\', s'))" thus "seqll i P ((\, s), a, (\', s'))" .. qed qed end