definition stable :: "'a set \ ('a \ 'a) set \ bool" where "stable \ \f g. (\x y. x \ f \ (x, y) \ g \ y \ f)"
inductive
rghoare :: "['a com, 'a set, ('a \ 'a) set, ('a \ 'a) set, 'a set] \ bool"
(\<open>\<turnstile> _ sat [_, _, _, _]\<close> [60,0,0,0,0] 45) where
Basic: "\ pre \ {s. f s \ post}; {(s,t). s \ pre \ (t=f s \ t=s)} \ guar;
stable pre rely; stable post rely \<rbrakk> \<Longrightarrow> \<turnstile> Basic f sat [pre, rely, guar, post]"
| Seq: "\ \ P sat [pre, rely, guar, mid]; \ Q sat [mid, rely, guar, post] \ \<Longrightarrow> \<turnstile> Seq P Q sat [pre, rely, guar, post]"
| Cond: "\ stable pre rely; \ P1 sat [pre \ b, rely, guar, post]; \<turnstile> P2 sat [pre \<inter> -b, rely, guar, post]; \<forall>s. (s,s)\<in>guar \<rbrakk> \<Longrightarrow> \<turnstile> Cond b P1 P2 sat [pre, rely, guar, post]"
| While: "\ stable pre rely; (pre \ -b) \ post; stable post rely; \<turnstile> P sat [pre \<inter> b, rely, guar, pre]; \<forall>s. (s,s)\<in>guar \<rbrakk> \<Longrightarrow> \<turnstile> While b P sat [pre, rely, guar, post]"
| Await: "\ stable pre rely; stable post rely; \<forall>V. \<turnstile> P sat [pre \<inter> b \<inter> {V}, {(s, t). s = t},
UNIV, {s. (V, s) \<in> guar} \<inter> post] \<rbrakk> \<Longrightarrow> \<turnstile> Await b P sat [pre, rely, guar, post]"
| Conseq: "\ pre \ pre'; rely \ rely'; guar' \ guar; post' \ post; \<turnstile> P sat [pre', rely', guar', post'] \<rbrakk> \<Longrightarrow> \<turnstile> P sat [pre, rely, guar, post]"
definitionPre :: "'a rgformula \ 'a set" where "Pre x \ fst(snd x)"
definitionPost :: "'a rgformula \ 'a set" where "Post x \ snd(snd(snd(snd x)))"
definition Rely :: "'a rgformula \ ('a \ 'a) set" where "Rely x \ fst(snd(snd x))"
definition Guar :: "'a rgformula \ ('a \ 'a) set" where "Guar x \ fst(snd(snd(snd x)))"
definition Com :: "'a rgformula \ 'a com" where "Com x \ fst x"
subsection \<open>Proof System for Parallel Programs\<close>
type_synonym'a par_rgformula = "('a rgformula) list \ 'a set \ ('a \ 'a) set \ ('a \ 'a) set \ 'a set"
inductive
par_rghoare :: "('a rgformula) list \ 'a set \ ('a \ 'a) set \ ('a \ 'a) set \ 'a set \ bool"
(\<open>\<turnstile> _ SAT [_, _, _, _]\<close> [60,0,0,0,0] 45) where
Parallel: "\ \i (\j\{j. j j\i}. Guar(xs!j)) \ Rely(xs!i);
(\<Union>j\<in>{j. j<length xs}. Guar(xs!j)) \<subseteq> guar; pre\<subseteq> (\<Inter>i\<in>{i. i<length xs}. Pre(xs!i));
(\<Inter>i\<in>{i. i<length xs}. Post(xs!i)) \<subseteq> post; \<forall>i<length xs. \<turnstile> Com(xs!i) sat [Pre(xs!i),Rely(xs!i),Guar(xs!i),Post(xs!i)] \<rbrakk> \<Longrightarrow> \<turnstile> xs SAT [pre, rely, guar, post]"
lemma Ex_first_occurrence [rule_format]: "P (n::nat) \ (\m. P m \ (\i P i))" apply(rule nat_less_induct) apply clarify apply(case_tac "\m. m \ P m") apply auto done
lemma stability [rule_format]: "\j k. x \ cptn \ stable p rely \ j\k \ k snd(x!j)\p \
(\<forall>i. (Suc i)<length x \<longrightarrow>
(x!i -e\<rightarrow> x!(Suc i)) \<longrightarrow> (snd(x!i), snd(x!(Suc i))) \<in> rely) \<longrightarrow>
(\<forall>i. j\<le>i \<and> i<k \<longrightarrow> x!i -e\<rightarrow> x!Suc i) \<longrightarrow> snd(x!k)\<in>p \<and> fst(x!j)=fst(x!k)"
supply [[simproc del: defined_all]] apply(induct x) apply clarify apply(force elim:cptn.cases) apply clarify apply(erule cptn.cases,simp) apply simp apply(case_tac k,simp,simp) apply(case_tac j,simp) apply(erule_tac x=0 in allE) apply(erule_tac x="nat"and P="\j. (0\j) \ (J j)" for J in allE,simp) apply(subgoal_tac "t\p") apply(subgoal_tac "(\i. i < length xs \ ((P, t) # xs) ! i -e\ xs ! i \ (snd (((P, t) # xs) ! i), snd (xs ! i)) \ rely)") apply clarify apply(erule_tac x="Suc i"and P="\j. (H j) \ (J j)\etran" for H J in allE,simp) apply clarify apply(erule_tac x="Suc i"and P="\j. (H j) \ (J j) \ (T j)\rely" for H J T in allE,simp) apply(erule_tac x=0 and P="\j. (H j) \ (J j)\etran \ T j" for H J T in allE,simp) apply(simp(no_asm_use) only:stable_def) apply(erule_tac x=s in allE) apply(erule_tac x=t in allE) apply simp apply(erule mp) apply(erule mp) apply(rule Env) apply simp apply(erule_tac x="nata"in allE) apply(erule_tac x="nat"and P="\j. (s\j) \ (J j)" for s J in allE,simp) apply(subgoal_tac "(\i. i < length xs \ ((P, t) # xs) ! i -e\ xs ! i \ (snd (((P, t) # xs) ! i), snd (xs ! i)) \ rely)") apply clarify apply(erule_tac x="Suc i"and P="\j. (H j) \ (J j)\etran" for H J in allE,simp) apply clarify apply(erule_tac x="Suc i"and P="\j. (H j) \ (J j) \ (T j)\rely" for H J T in allE,simp) apply(case_tac k,simp,simp) apply(case_tac j) apply(erule_tac x=0 and P="\j. (H j) \ (J j)\etran" for H J in allE,simp) apply(erule etran.cases,simp) apply(erule_tac x="nata"in allE) apply(erule_tac x="nat"and P="\j. (s\j) \ (J j)" for s J in allE,simp) apply(subgoal_tac "(\i. i < length xs \ ((Q, t) # xs) ! i -e\ xs ! i \ (snd (((Q, t) # xs) ! i), snd (xs ! i)) \ rely)") apply clarify apply(erule_tac x="Suc i"and P="\j. (H j) \ (J j)\etran" for H J in allE,simp) apply clarify apply(erule_tac x="Suc i"and P="\j. (H j) \ (J j) \ (T j)\rely" for H J T in allE,simp) done
subsection \<open>Soundness of the System for Component Programs\<close>
subsubsection \<open>Soundness of the Basic rule\<close>
lemma unique_ctran_Basic [rule_format]: "\s i. x \ cptn \ x ! 0 = (Some (Basic f), s) \
Suc i<length x \<longrightarrow> x!i -c\<rightarrow> x!Suc i \<longrightarrow>
(\<forall>j. Suc j<length x \<longrightarrow> i\<noteq>j \<longrightarrow> x!j -e\<rightarrow> x!Suc j)" apply(induct x,simp) apply simp apply clarify apply(erule cptn.cases,simp) apply(case_tac i,simp+) apply clarify apply(case_tac j,simp) apply(rule Env) apply simp apply clarify apply simp apply(case_tac i) apply(case_tac j,simp,simp) apply(erule ctran.cases,simp_all) apply(force elim: not_ctran_None) apply(ind_cases "((Some (Basic f), sa), Q, t) \ ctran" for sa Q t) apply simp apply(drule_tac i=nat in not_ctran_None,simp) apply(erule etranE,simp) done
lemma exists_ctran_Basic_None [rule_format]: "\s i. x \ cptn \ x ! 0 = (Some (Basic f), s) \<longrightarrow> i<length x \<longrightarrow> fst(x!i)=None \<longrightarrow> (\<exists>j<i. x!j -c\<rightarrow> x!Suc j)" apply(induct x,simp) apply simp apply clarify apply(erule cptn.cases,simp) apply(case_tac i,simp,simp) apply(erule_tac x=nat in allE,simp) apply clarify apply(rule_tac x="Suc j"in exI,simp,simp) apply clarify apply(case_tac i,simp,simp) apply(rule_tac x=0 in exI,simp) done
lemma Basic_sound: " \pre \ {s. f s \ post}; {(s, t). s \ pre \ t = f s} \ guar;
stable pre rely; stable post rely\<rbrakk> \<Longrightarrow> \<Turnstile> Basic f sat [pre, rely, guar, post]"
supply [[simproc del: defined_all]] apply(unfold com_validity_def) apply clarify apply(simp add:comm_def) apply(rule conjI) apply clarify apply(simp add:cp_def assum_def) apply clarify apply(frule_tac j=0 and k=i and p=prein stability) apply simp_all apply(erule_tac x=ia in allE,simp) apply(erule_tac i=i and f=f in unique_ctran_Basic,simp_all) apply(erule subsetD,simp) apply(case_tac "x!i") apply clarify apply(drule_tac s="Some (Basic f)"in sym,simp) apply(thin_tac "\j. H j" for H) apply(force elim:ctran.cases) apply clarify apply(simp add:cp_def) apply clarify apply(frule_tac i="length x - 1"and f=f in exists_ctran_Basic_None,simp+) apply(case_tac x,simp+) apply(rule last_fst_esp,simp add:last_length) apply (case_tac x,simp+) apply(simp add:assum_def) apply clarify apply(frule_tac j=0 and k="j"and p=prein stability) apply simp_all apply(erule_tac x=i in allE,simp) apply(erule_tac i=j and f=f in unique_ctran_Basic,simp_all) apply(case_tac "x!j") apply clarify apply simp apply(drule_tac s="Some (Basic f)"in sym,simp) apply(case_tac "x!Suc j",simp) apply(rule ctran.cases,simp) apply(simp_all) apply(drule_tac c=sa in subsetD,simp) apply clarify apply(frule_tac j="Suc j"and k="length x - 1"and p=postin stability,simp_all) apply(case_tac x,simp+) apply(erule_tac x=i in allE) apply(erule_tac i=j and f=f in unique_ctran_Basic,simp_all) apply arith+ apply(case_tac x) apply(simp add:last_length)+ done
subsubsection\<open>Soundness of the Await rule\<close>
lemma unique_ctran_Await [rule_format]: "\s i. x \ cptn \ x ! 0 = (Some (Await b c), s) \
Suc i<length x \<longrightarrow> x!i -c\<rightarrow> x!Suc i \<longrightarrow>
(\<forall>j. Suc j<length x \<longrightarrow> i\<noteq>j \<longrightarrow> x!j -e\<rightarrow> x!Suc j)" apply(induct x,simp+) apply clarify apply(erule cptn.cases,simp) apply(case_tac i,simp+) apply clarify apply(case_tac j,simp) apply(rule Env) apply simp apply clarify apply simp apply(case_tac i) apply(case_tac j,simp,simp) apply(erule ctran.cases,simp_all) apply(force elim: not_ctran_None) apply(ind_cases "((Some (Await b c), sa), Q, t) \ ctran" for sa Q t,simp) apply(drule_tac i=nat in not_ctran_None,simp) apply(erule etranE,simp) done
lemma exists_ctran_Await_None [rule_format]: "\s i. x \ cptn \ x ! 0 = (Some (Await b c), s) \<longrightarrow> i<length x \<longrightarrow> fst(x!i)=None \<longrightarrow> (\<exists>j<i. x!j -c\<rightarrow> x!Suc j)" apply(induct x,simp+) apply clarify apply(erule cptn.cases,simp) apply(case_tac i,simp+) apply(erule_tac x=nat in allE,simp) apply clarify apply(rule_tac x="Suc j"in exI,simp,simp) apply clarify apply(case_tac i,simp,simp) apply(rule_tac x=0 in exI,simp) done
lemma While_sound: "\stable pre rely; pre \ - b \ post; stable post rely; \<Turnstile> P sat [pre \<inter> b, rely, guar, pre]; \<forall>s. (s,s)\<in>guar\<rbrakk> \<Longrightarrow> \<Turnstile> While b P sat [pre, rely, guar, post]" apply(unfold com_validity_def) apply clarify apply(erule_tac xs="tl x"in While_sound_aux) apply(simp add:com_validity_def) apply force apply simp_all apply(simp add:cptn_iff_cptn_mod cp_def) apply(simp add:cp_def) apply clarify apply(rule nth_equalityI) apply simp_all apply(case_tac x,simp+) apply(case_tac i,simp+) apply(case_tac x,simp+) done
subsubsection\<open>Soundness of the Rule of Consequence\<close>
lemma Conseq_sound: "\pre \ pre'; rely \ rely'; guar' \ guar; post' \ post; \<Turnstile> P sat [pre', rely', guar', post']\<rbrakk> \<Longrightarrow> \<Turnstile> P sat [pre, rely, guar, post]" apply(simp add:com_validity_def assum_def comm_def) apply clarify apply(erule_tac x=s in allE) apply(drule_tac c=x in subsetD) apply force apply force done
subsubsection \<open>Soundness of the system for sequential component programs\<close>
theorem rgsound: "\ P sat [pre, rely, guar, post] \ \ P sat [pre, rely, guar, post]" apply(erule rghoare.induct) apply(force elim:Basic_sound) apply(force elim:Seq_sound) apply(force elim:Cond_sound) apply(force elim:While_sound) apply(force elim:Await_sound) apply(erule Conseq_sound,simp+) done
subsection \<open>Soundness of the System for Parallel Programs\<close>
definition ParallelCom :: "('a rgformula) list \ 'a par_com" where "ParallelCom Ps \ map (Some \ fst) Ps"
lemma two: "\ \i (\j\{j. j < length xs \ j \ i}. Guar (xs ! j)) \<subseteq> Rely (xs ! i); pre\<subseteq> (\<Inter>i\<in>{i. i < length xs}. Pre (xs ! i)); \<forall>i<length xs. \<Turnstile> Com (xs ! i) sat [Pre (xs ! i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i)];
length xs=length clist; x \<in> par_cp (ParallelCom xs) s; x\<in>par_assum(pre, rely); \<forall>i<length clist. clist!i\<in>cp (Some(Com(xs!i))) s; x \<propto> clist \<rbrakk> \<Longrightarrow> \<forall>j i. i<length clist \<and> Suc j<length x \<longrightarrow> (clist!i!j) -c\<rightarrow> (clist!i!Suc j) \<longrightarrow> (snd(clist!i!j), snd(clist!i!Suc j)) \<in> Guar(xs!i)" apply(unfold par_cp_def) apply (rule ccontr) \<comment> \<open>By contradiction:\<close> apply simp apply(erule exE) \<comment> \<open>the first c-tran that does not satisfy the guarantee-condition is from \<open>\<sigma>_i\<close> at step \<open>m\<close>.\<close> apply(drule_tac n=j and P="\j. \i. H i j" for H in Ex_first_occurrence) apply(erule exE) apply clarify \<comment> \<open>\<open>\<sigma>_i \<in> A(pre, rely_1)\<close>\<close> apply(subgoal_tac "take (Suc (Suc m)) (clist!i) \ assum(Pre(xs!i), Rely(xs!i))") \<comment> \<open>but this contradicts \<open>\<Turnstile> \<sigma>_i sat [pre_i,rely_i,guar_i,post_i]\<close>\<close> apply(erule_tac x=i and P="\i. H i \ \ (J i) sat [I i,K i,M i,N i]" for H J I K M N in allE,erule impE,assumption) apply(simp add:com_validity_def) apply(erule_tac x=s in allE) apply(simp add:cp_def comm_def) apply(drule_tac c="take (Suc (Suc m)) (clist ! i)"in subsetD) apply simp apply (blast intro: takecptn_is_cptn) apply simp apply clarify apply(erule_tac x=m and P="\j. I j \ J j \ H j" for I J H in allE) apply (simp add:conjoin_def same_length_def) apply(simp add:assum_def) apply(rule conjI) apply(erule_tac x=i and P="\j. H j \ I j \cp (K j) (J j)" for H I K J in allE) apply(simp add:cp_def par_assum_def) apply(drule_tac c="s"in subsetD,simp) apply simp apply clarify apply(erule_tac x=i and P="\j. H j \ M \ \((T j) ` (S j)) \ (L j)" for H M S T L in allE) apply simp apply(erule subsetD) apply simp apply(simp add:conjoin_def compat_label_def) apply clarify apply(erule_tac x=ia and P="\j. H j \ (P j) \ Q j" for H P Q in allE,simp) \<comment> \<open>each etran in \<open>\<sigma>_1[0\<dots>m]\<close> corresponds to\<close> apply(erule disjE) \<comment> \<open>a c-tran in some \<open>\<sigma>_{ib}\<close>\<close> apply clarify apply(case_tac "i=ib",simp) apply(erule etranE,simp) apply(erule_tac x="ib"and P="\i. H i \ (I i) \ (J i)" for H I J in allE) apply (erule etranE) apply(case_tac "ia=m",simp) apply simp apply(erule_tac x=ia and P="\j. H j \ (\i. P i j)" for H P in allE) apply(subgoal_tac "ia,simp) prefer 2 apply arith apply(erule_tac x=ib and P="\j. (I j, H j) \ ctran \ P i j" for I H P in allE,simp) apply(simp add:same_state_def) apply(erule_tac x=i and P="\j. (T j) \ (\i. (H j i) \ (snd (d j i))=(snd (e j i)))" for T H d e in all_dupE) apply(erule_tac x=ib and P="\j. (T j) \ (\i. (H j i) \ (snd (d j i))=(snd (e j i)))" for T H d e in allE,simp) \<comment> \<open>or an e-tran in \<open>\<sigma>\<close>,
therefore it satisfies \<open>rely \<or> guar_{ib}\<close>\<close> apply (force simp add:par_assum_def same_state_def) done
lemma three [rule_format]: "\ xs\[]; \i (\j\{j. j < length xs \ j \ i}. Guar (xs ! j)) \<subseteq> Rely (xs ! i); pre\<subseteq> (\<Inter>i\<in>{i. i < length xs}. Pre (xs ! i)); \<forall>i<length xs. \<Turnstile> Com (xs ! i) sat [Pre (xs ! i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i)];
length xs=length clist; x \<in> par_cp (ParallelCom xs) s; x \<in> par_assum(pre, rely); \<forall>i<length clist. clist!i\<in>cp (Some(Com(xs!i))) s; x \<propto> clist \<rbrakk> \<Longrightarrow> \<forall>j i. i<length clist \<and> Suc j<length x \<longrightarrow> (clist!i!j) -e\<rightarrow> (clist!i!Suc j) \<longrightarrow> (snd(clist!i!j), snd(clist!i!Suc j)) \<in> rely \<union> (\<Union>j\<in>{j. j < length xs \<and> j \<noteq> i}. Guar (xs ! j))" apply(drule two) apply simp_all apply clarify apply(simp add:conjoin_def compat_label_def) apply clarify apply(erule_tac x=j and P="\j. H j \ (J j \ (\i. P i j)) \ I j" for H J P I in allE,simp) apply(erule disjE) prefer 2 apply(force simp add:same_state_def par_assum_def) apply clarify apply(case_tac "i=ia",simp) apply(erule etranE,simp) apply(erule_tac x="ia"and P="\i. H i \ (I i) \ (J i)" for H I J in allE,simp) apply(erule_tac x=j and P="\j. \i. S j i \ (I j i, H j i) \ ctran \ P i j" for S I H P in allE) apply(erule_tac x=ia and P="\j. S j \ (I j, H j) \ ctran \ P j" for S I H P in allE) apply(simp add:same_state_def) apply(erule_tac x=i and P="\j. T j \ (\i. H j i \ (snd (d j i))=(snd (e j i)))" for T H d e in all_dupE) apply(erule_tac x=ia and P="\j. T j \ (\i. H j i \ (snd (d j i))=(snd (e j i)))" for T H d e in allE,simp) done
lemma four: "\xs\[]; \i < length xs. rely \ (\j\{j. j < length xs \ j \ i}. Guar (xs ! j)) \<subseteq> Rely (xs ! i);
(\<Union>j\<in>{j. j < length xs}. Guar (xs ! j)) \<subseteq> guar; pre\<subseteq> (\<Inter>i\<in>{i. i < length xs}. Pre (xs ! i)); \<forall>i < length xs. \<Turnstile> Com (xs ! i) sat [Pre (xs ! i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i)];
x \<in> par_cp (ParallelCom xs) s; x \<in> par_assum (pre, rely); Suc i < length x;
x ! i -pc\<rightarrow> x ! Suc i\<rbrakk> \<Longrightarrow> (snd (x ! i), snd (x ! Suc i)) \<in> guar" apply(simp add: ParallelCom_def) apply(subgoal_tac "(map (Some \ fst) xs)\[]") prefer 2 apply simp apply(frule rev_subsetD) apply(erule one [THEN equalityD1]) apply(erule subsetD) apply simp apply clarify apply(drule_tac pre=preand rely=rely and x=x and s=s and xs=xs and clist=clist in two) apply(assumption+) apply(erule sym) apply(simp add:ParallelCom_def) apply assumption apply(simp add:Com_def) apply assumption apply(simp add:conjoin_def same_program_def) apply clarify apply(erule_tac x=i and P="\j. H j \ fst(I j)=(J j)" for H I J in all_dupE) apply(erule_tac x="Suc i"and P="\j. H j \ fst(I j)=(J j)" for H I J in allE) apply(erule par_ctranE,simp) apply(erule_tac x=i and P="\j. \i. S j i \ (I j i, H j i) \ ctran \ P i j" for S I H P in allE) apply(erule_tac x=ia and P="\j. S j \ (I j, H j) \ ctran \ P j" for S I H P in allE) apply(rule_tac x=ia in exI) apply(simp add:same_state_def) apply(erule_tac x=ia and P="\j. T j \ (\i. H j i \ (snd (d j i))=(snd (e j i)))" for T H d e in all_dupE,simp) apply(erule_tac x=ia and P="\j. T j \ (\i. H j i \ (snd (d j i))=(snd (e j i)))" for T H d e in allE,simp) apply(erule_tac x=i and P="\j. H j \ (snd (d j))=(snd (e j))" for H d e in all_dupE) apply(erule_tac x=i and P="\j. H j \ (snd (d j))=(snd (e j))" for H d e in all_dupE,simp) apply(erule_tac x="Suc i"and P="\j. H j \ (snd (d j))=(snd (e j))" for H d e in allE,simp) apply(erule mp) apply(subgoal_tac "r=fst(clist ! ia ! Suc i)",simp) apply(drule_tac i=ia in list_eq_if) back apply simp_all done
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.