src/HOL/Hoare_Parallel/RG_Tran.thy
author wenzelm
Wed Mar 30 23:26:40 2011 +0200 (2011-03-30)
changeset 42174 d0be2722ce9f
parent 41842 d8f76db6a207
child 51119 6b2352111017
permissions -rw-r--r--
modernized specifications;
     1 header {* \section{Operational Semantics} *}
     2 
     3 theory RG_Tran
     4 imports RG_Com
     5 begin
     6 
     7 subsection {* Semantics of Component Programs *}
     8 
     9 subsubsection {* Environment transitions *}
    10 
    11 type_synonym 'a conf = "(('a com) option) \<times> 'a"
    12 
    13 inductive_set
    14   etran :: "('a conf \<times> 'a conf) set" 
    15   and etran' :: "'a conf \<Rightarrow> 'a conf \<Rightarrow> bool"  ("_ -e\<rightarrow> _" [81,81] 80)
    16 where
    17   "P -e\<rightarrow> Q \<equiv> (P,Q) \<in> etran"
    18 | Env: "(P, s) -e\<rightarrow> (P, t)"
    19 
    20 lemma etranE: "c -e\<rightarrow> c' \<Longrightarrow> (\<And>P s t. c = (P, s) \<Longrightarrow> c' = (P, t) \<Longrightarrow> Q) \<Longrightarrow> Q"
    21   by (induct c, induct c', erule etran.cases, blast)
    22 
    23 subsubsection {* Component transitions *}
    24 
    25 inductive_set
    26   ctran :: "('a conf \<times> 'a conf) set"
    27   and ctran' :: "'a conf \<Rightarrow> 'a conf \<Rightarrow> bool"   ("_ -c\<rightarrow> _" [81,81] 80)
    28   and ctrans :: "'a conf \<Rightarrow> 'a conf \<Rightarrow> bool"   ("_ -c*\<rightarrow> _" [81,81] 80)
    29 where
    30   "P -c\<rightarrow> Q \<equiv> (P,Q) \<in> ctran"
    31 | "P -c*\<rightarrow> Q \<equiv> (P,Q) \<in> ctran^*"
    32 
    33 | Basic:  "(Some(Basic f), s) -c\<rightarrow> (None, f s)"
    34 
    35 | Seq1:   "(Some P0, s) -c\<rightarrow> (None, t) \<Longrightarrow> (Some(Seq P0 P1), s) -c\<rightarrow> (Some P1, t)"
    36 
    37 | Seq2:   "(Some P0, s) -c\<rightarrow> (Some P2, t) \<Longrightarrow> (Some(Seq P0 P1), s) -c\<rightarrow> (Some(Seq P2 P1), t)"
    38 
    39 | CondT: "s\<in>b  \<Longrightarrow> (Some(Cond b P1 P2), s) -c\<rightarrow> (Some P1, s)"
    40 | CondF: "s\<notin>b \<Longrightarrow> (Some(Cond b P1 P2), s) -c\<rightarrow> (Some P2, s)"
    41 
    42 | WhileF: "s\<notin>b \<Longrightarrow> (Some(While b P), s) -c\<rightarrow> (None, s)"
    43 | WhileT: "s\<in>b  \<Longrightarrow> (Some(While b P), s) -c\<rightarrow> (Some(Seq P (While b P)), s)"
    44 
    45 | Await:  "\<lbrakk>s\<in>b; (Some P, s) -c*\<rightarrow> (None, t)\<rbrakk> \<Longrightarrow> (Some(Await b P), s) -c\<rightarrow> (None, t)" 
    46 
    47 monos "rtrancl_mono"
    48 
    49 subsection {* Semantics of Parallel Programs *}
    50 
    51 type_synonym 'a par_conf = "('a par_com) \<times> 'a"
    52 
    53 inductive_set
    54   par_etran :: "('a par_conf \<times> 'a par_conf) set"
    55   and par_etran' :: "['a par_conf,'a par_conf] \<Rightarrow> bool" ("_ -pe\<rightarrow> _" [81,81] 80)
    56 where
    57   "P -pe\<rightarrow> Q \<equiv> (P,Q) \<in> par_etran"
    58 | ParEnv:  "(Ps, s) -pe\<rightarrow> (Ps, t)"
    59 
    60 inductive_set
    61   par_ctran :: "('a par_conf \<times> 'a par_conf) set"
    62   and par_ctran' :: "['a par_conf,'a par_conf] \<Rightarrow> bool" ("_ -pc\<rightarrow> _" [81,81] 80)
    63 where
    64   "P -pc\<rightarrow> Q \<equiv> (P,Q) \<in> par_ctran"
    65 | ParComp: "\<lbrakk>i<length Ps; (Ps!i, s) -c\<rightarrow> (r, t)\<rbrakk> \<Longrightarrow> (Ps, s) -pc\<rightarrow> (Ps[i:=r], t)"
    66 
    67 lemma par_ctranE: "c -pc\<rightarrow> c' \<Longrightarrow>
    68   (\<And>i Ps s r t. c = (Ps, s) \<Longrightarrow> c' = (Ps[i := r], t) \<Longrightarrow> i < length Ps \<Longrightarrow>
    69      (Ps ! i, s) -c\<rightarrow> (r, t) \<Longrightarrow> P) \<Longrightarrow> P"
    70   by (induct c, induct c', erule par_ctran.cases, blast)
    71 
    72 subsection {* Computations *}
    73 
    74 subsubsection {* Sequential computations *}
    75 
    76 type_synonym 'a confs = "'a conf list"
    77 
    78 inductive_set cptn :: "'a confs set"
    79 where
    80   CptnOne: "[(P,s)] \<in> cptn"
    81 | CptnEnv: "(P, t)#xs \<in> cptn \<Longrightarrow> (P,s)#(P,t)#xs \<in> cptn"
    82 | CptnComp: "\<lbrakk>(P,s) -c\<rightarrow> (Q,t); (Q, t)#xs \<in> cptn \<rbrakk> \<Longrightarrow> (P,s)#(Q,t)#xs \<in> cptn"
    83 
    84 definition cp :: "('a com) option \<Rightarrow> 'a \<Rightarrow> ('a confs) set" where
    85   "cp P s \<equiv> {l. l!0=(P,s) \<and> l \<in> cptn}"  
    86 
    87 subsubsection {* Parallel computations *}
    88 
    89 type_synonym 'a par_confs = "'a par_conf list"
    90 
    91 inductive_set par_cptn :: "'a par_confs set"
    92 where
    93   ParCptnOne: "[(P,s)] \<in> par_cptn"
    94 | ParCptnEnv: "(P,t)#xs \<in> par_cptn \<Longrightarrow> (P,s)#(P,t)#xs \<in> par_cptn"
    95 | ParCptnComp: "\<lbrakk> (P,s) -pc\<rightarrow> (Q,t); (Q,t)#xs \<in> par_cptn \<rbrakk> \<Longrightarrow> (P,s)#(Q,t)#xs \<in> par_cptn"
    96 
    97 definition par_cp :: "'a par_com \<Rightarrow> 'a \<Rightarrow> ('a par_confs) set" where
    98   "par_cp P s \<equiv> {l. l!0=(P,s) \<and> l \<in> par_cptn}"  
    99 
   100 subsection{* Modular Definition of Computation *}
   101 
   102 definition lift :: "'a com \<Rightarrow> 'a conf \<Rightarrow> 'a conf" where
   103   "lift Q \<equiv> \<lambda>(P, s). (if P=None then (Some Q,s) else (Some(Seq (the P) Q), s))"
   104 
   105 inductive_set cptn_mod :: "('a confs) set"
   106 where
   107   CptnModOne: "[(P, s)] \<in> cptn_mod"
   108 | CptnModEnv: "(P, t)#xs \<in> cptn_mod \<Longrightarrow> (P, s)#(P, t)#xs \<in> cptn_mod"
   109 | CptnModNone: "\<lbrakk>(Some P, s) -c\<rightarrow> (None, t); (None, t)#xs \<in> cptn_mod \<rbrakk> \<Longrightarrow> (Some P,s)#(None, t)#xs \<in>cptn_mod"
   110 | CptnModCondT: "\<lbrakk>(Some P0, s)#ys \<in> cptn_mod; s \<in> b \<rbrakk> \<Longrightarrow> (Some(Cond b P0 P1), s)#(Some P0, s)#ys \<in> cptn_mod"
   111 | CptnModCondF: "\<lbrakk>(Some P1, s)#ys \<in> cptn_mod; s \<notin> b \<rbrakk> \<Longrightarrow> (Some(Cond b P0 P1), s)#(Some P1, s)#ys \<in> cptn_mod"
   112 | CptnModSeq1: "\<lbrakk>(Some P0, s)#xs \<in> cptn_mod; zs=map (lift P1) xs \<rbrakk>
   113                  \<Longrightarrow> (Some(Seq P0 P1), s)#zs \<in> cptn_mod"
   114 | CptnModSeq2: 
   115   "\<lbrakk>(Some P0, s)#xs \<in> cptn_mod; fst(last ((Some P0, s)#xs)) = None; 
   116   (Some P1, snd(last ((Some P0, s)#xs)))#ys \<in> cptn_mod; 
   117   zs=(map (lift P1) xs)@ys \<rbrakk> \<Longrightarrow> (Some(Seq P0 P1), s)#zs \<in> cptn_mod"
   118 
   119 | CptnModWhile1: 
   120   "\<lbrakk> (Some P, s)#xs \<in> cptn_mod; s \<in> b; zs=map (lift (While b P)) xs \<rbrakk> 
   121   \<Longrightarrow> (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs \<in> cptn_mod"
   122 | CptnModWhile2: 
   123   "\<lbrakk> (Some P, s)#xs \<in> cptn_mod; fst(last ((Some P, s)#xs))=None; s \<in> b; 
   124   zs=(map (lift (While b P)) xs)@ys; 
   125   (Some(While b P), snd(last ((Some P, s)#xs)))#ys \<in> cptn_mod\<rbrakk> 
   126   \<Longrightarrow> (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs \<in> cptn_mod"
   127 
   128 subsection {* Equivalence of Both Definitions.*}
   129 
   130 lemma last_length: "((a#xs)!(length xs))=last (a#xs)"
   131 apply simp
   132 apply(induct xs,simp+)
   133 done
   134 
   135 lemma div_seq [rule_format]: "list \<in> cptn_mod \<Longrightarrow>
   136  (\<forall>s P Q zs. list=(Some (Seq P Q), s)#zs \<longrightarrow>
   137   (\<exists>xs. (Some P, s)#xs \<in> cptn_mod  \<and> (zs=(map (lift Q) xs) \<or>
   138   ( fst(((Some P, s)#xs)!length xs)=None \<and> 
   139   (\<exists>ys. (Some Q, snd(((Some P, s)#xs)!length xs))#ys \<in> cptn_mod  
   140   \<and> zs=(map (lift (Q)) xs)@ys)))))"
   141 apply(erule cptn_mod.induct)
   142 apply simp_all
   143     apply clarify
   144     apply(force intro:CptnModOne)
   145    apply clarify
   146    apply(erule_tac x=Pa in allE)
   147    apply(erule_tac x=Q in allE)
   148    apply simp
   149    apply clarify
   150    apply(erule disjE)
   151     apply(rule_tac x="(Some Pa,t)#xsa" in exI)
   152     apply(rule conjI)
   153      apply clarify
   154      apply(erule CptnModEnv)
   155     apply(rule disjI1)
   156     apply(simp add:lift_def)
   157    apply clarify
   158    apply(rule_tac x="(Some Pa,t)#xsa" in exI)
   159    apply(rule conjI)
   160     apply(erule CptnModEnv)
   161    apply(rule disjI2)
   162    apply(rule conjI)
   163     apply(case_tac xsa,simp,simp)
   164    apply(rule_tac x="ys" in exI)
   165    apply(rule conjI)
   166     apply simp
   167    apply(simp add:lift_def)
   168   apply clarify
   169   apply(erule ctran.cases,simp_all)
   170  apply clarify
   171  apply(rule_tac x="xs" in exI)
   172  apply simp
   173  apply clarify
   174 apply(rule_tac x="xs" in exI)
   175 apply(simp add: last_length)
   176 done
   177 
   178 lemma cptn_onlyif_cptn_mod_aux [rule_format]:
   179   "\<forall>s Q t xs.((Some a, s), Q, t) \<in> ctran \<longrightarrow> (Q, t) # xs \<in> cptn_mod 
   180   \<longrightarrow> (Some a, s) # (Q, t) # xs \<in> cptn_mod"
   181 apply(induct a)
   182 apply simp_all
   183 --{* basic *}
   184 apply clarify
   185 apply(erule ctran.cases,simp_all)
   186 apply(rule CptnModNone,rule Basic,simp)
   187 apply clarify
   188 apply(erule ctran.cases,simp_all)
   189 --{* Seq1 *}
   190 apply(rule_tac xs="[(None,ta)]" in CptnModSeq2)
   191   apply(erule CptnModNone)
   192   apply(rule CptnModOne)
   193  apply simp
   194 apply simp
   195 apply(simp add:lift_def)
   196 --{* Seq2 *}
   197 apply(erule_tac x=sa in allE)
   198 apply(erule_tac x="Some P2" in allE)
   199 apply(erule allE,erule impE, assumption)
   200 apply(drule div_seq,simp)
   201 apply force
   202 apply clarify
   203 apply(erule disjE)
   204  apply clarify
   205  apply(erule allE,erule impE, assumption)
   206  apply(erule_tac CptnModSeq1)
   207  apply(simp add:lift_def)
   208 apply clarify 
   209 apply(erule allE,erule impE, assumption)
   210 apply(erule_tac CptnModSeq2)
   211   apply (simp add:last_length)
   212  apply (simp add:last_length)
   213 apply(simp add:lift_def)
   214 --{* Cond *}
   215 apply clarify
   216 apply(erule ctran.cases,simp_all)
   217 apply(force elim: CptnModCondT)
   218 apply(force elim: CptnModCondF)
   219 --{* While *}
   220 apply  clarify
   221 apply(erule ctran.cases,simp_all)
   222 apply(rule CptnModNone,erule WhileF,simp)
   223 apply(drule div_seq,force)
   224 apply clarify
   225 apply (erule disjE)
   226  apply(force elim:CptnModWhile1)
   227 apply clarify
   228 apply(force simp add:last_length elim:CptnModWhile2)
   229 --{* await *}
   230 apply clarify
   231 apply(erule ctran.cases,simp_all)
   232 apply(rule CptnModNone,erule Await,simp+)
   233 done
   234 
   235 lemma cptn_onlyif_cptn_mod [rule_format]: "c \<in> cptn \<Longrightarrow> c \<in> cptn_mod"
   236 apply(erule cptn.induct)
   237   apply(rule CptnModOne)
   238  apply(erule CptnModEnv)
   239 apply(case_tac P)
   240  apply simp
   241  apply(erule ctran.cases,simp_all)
   242 apply(force elim:cptn_onlyif_cptn_mod_aux)
   243 done
   244 
   245 lemma lift_is_cptn: "c\<in>cptn \<Longrightarrow> map (lift P) c \<in> cptn"
   246 apply(erule cptn.induct)
   247   apply(force simp add:lift_def CptnOne)
   248  apply(force intro:CptnEnv simp add:lift_def)
   249 apply(force simp add:lift_def intro:CptnComp Seq2 Seq1 elim:ctran.cases)
   250 done
   251 
   252 lemma cptn_append_is_cptn [rule_format]: 
   253  "\<forall>b a. b#c1\<in>cptn \<longrightarrow>  a#c2\<in>cptn \<longrightarrow> (b#c1)!length c1=a \<longrightarrow> b#c1@c2\<in>cptn"
   254 apply(induct c1)
   255  apply simp
   256 apply clarify
   257 apply(erule cptn.cases,simp_all)
   258  apply(force intro:CptnEnv)
   259 apply(force elim:CptnComp)
   260 done
   261 
   262 lemma last_lift: "\<lbrakk>xs\<noteq>[]; fst(xs!(length xs - (Suc 0)))=None\<rbrakk> 
   263  \<Longrightarrow> fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=(Some P)"
   264 apply(case_tac "(xs ! (length xs - (Suc 0)))")
   265 apply (simp add:lift_def)
   266 done
   267 
   268 lemma last_fst [rule_format]: "P((a#x)!length x) \<longrightarrow> \<not>P a \<longrightarrow> P (x!(length x - (Suc 0)))" 
   269 apply(induct x,simp+)
   270 done
   271 
   272 lemma last_fst_esp: 
   273  "fst(((Some a,s)#xs)!(length xs))=None \<Longrightarrow> fst(xs!(length xs - (Suc 0)))=None" 
   274 apply(erule last_fst)
   275 apply simp
   276 done
   277 
   278 lemma last_snd: "xs\<noteq>[] \<Longrightarrow> 
   279   snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))"
   280 apply(case_tac "(xs ! (length xs - (Suc 0)))",simp)
   281 apply (simp add:lift_def)
   282 done
   283 
   284 lemma Cons_lift: "(Some (Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((Some P, s) # xs)"
   285 by(simp add:lift_def)
   286 
   287 lemma Cons_lift_append: 
   288   "(Some (Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((Some P, s) # xs)@ ys "
   289 by(simp add:lift_def)
   290 
   291 lemma lift_nth: "i<length xs \<Longrightarrow> map (lift Q) xs ! i = lift Q  (xs! i)"
   292 by (simp add:lift_def)
   293 
   294 lemma snd_lift: "i< length xs \<Longrightarrow> snd(lift Q (xs ! i))= snd (xs ! i)"
   295 apply(case_tac "xs!i")
   296 apply(simp add:lift_def)
   297 done
   298 
   299 lemma cptn_if_cptn_mod: "c \<in> cptn_mod \<Longrightarrow> c \<in> cptn"
   300 apply(erule cptn_mod.induct)
   301         apply(rule CptnOne)
   302        apply(erule CptnEnv)
   303       apply(erule CptnComp,simp)
   304      apply(rule CptnComp)
   305       apply(erule CondT,simp)
   306     apply(rule CptnComp)
   307      apply(erule CondF,simp)
   308 --{* Seq1 *}
   309 apply(erule cptn.cases,simp_all)
   310   apply(rule CptnOne)
   311  apply clarify
   312  apply(drule_tac P=P1 in lift_is_cptn)
   313  apply(simp add:lift_def)
   314  apply(rule CptnEnv,simp)
   315 apply clarify
   316 apply(simp add:lift_def)
   317 apply(rule conjI)
   318  apply clarify
   319  apply(rule CptnComp)
   320   apply(rule Seq1,simp)
   321  apply(drule_tac P=P1 in lift_is_cptn)
   322  apply(simp add:lift_def)
   323 apply clarify
   324 apply(rule CptnComp)
   325  apply(rule Seq2,simp)
   326 apply(drule_tac P=P1 in lift_is_cptn)
   327 apply(simp add:lift_def)
   328 --{* Seq2 *}
   329 apply(rule cptn_append_is_cptn)
   330   apply(drule_tac P=P1 in lift_is_cptn)
   331   apply(simp add:lift_def)
   332  apply simp
   333 apply(simp split: split_if_asm)
   334 apply(frule_tac P=P1 in last_lift)
   335  apply(rule last_fst_esp)
   336  apply (simp add:last_length)
   337 apply(simp add:Cons_lift lift_def split_def last_conv_nth)
   338 --{* While1 *}
   339 apply(rule CptnComp)
   340  apply(rule WhileT,simp)
   341 apply(drule_tac P="While b P" in lift_is_cptn)
   342 apply(simp add:lift_def)
   343 --{* While2 *}
   344 apply(rule CptnComp)
   345  apply(rule WhileT,simp)
   346 apply(rule cptn_append_is_cptn)
   347   apply(drule_tac P="While b P" in lift_is_cptn)
   348   apply(simp add:lift_def)
   349  apply simp
   350 apply(simp split: split_if_asm)
   351 apply(frule_tac P="While b P" in last_lift)
   352  apply(rule last_fst_esp,simp add:last_length)
   353 apply(simp add:Cons_lift lift_def split_def last_conv_nth)
   354 done
   355 
   356 theorem cptn_iff_cptn_mod: "(c \<in> cptn) = (c \<in> cptn_mod)"
   357 apply(rule iffI)
   358  apply(erule cptn_onlyif_cptn_mod)
   359 apply(erule cptn_if_cptn_mod)
   360 done
   361 
   362 section {* Validity  of Correctness Formulas*}
   363 
   364 subsection {* Validity for Component Programs. *}
   365 
   366 type_synonym 'a rgformula =
   367   "'a com \<times> 'a set \<times> ('a \<times> 'a) set \<times> ('a \<times> 'a) set \<times> 'a set"
   368 
   369 definition assum :: "('a set \<times> ('a \<times> 'a) set) \<Rightarrow> ('a confs) set" where
   370   "assum \<equiv> \<lambda>(pre, rely). {c. snd(c!0) \<in> pre \<and> (\<forall>i. Suc i<length c \<longrightarrow> 
   371                c!i -e\<rightarrow> c!(Suc i) \<longrightarrow> (snd(c!i), snd(c!Suc i)) \<in> rely)}"
   372 
   373 definition comm :: "(('a \<times> 'a) set \<times> 'a set) \<Rightarrow> ('a confs) set" where
   374   "comm \<equiv> \<lambda>(guar, post). {c. (\<forall>i. Suc i<length c \<longrightarrow> 
   375                c!i -c\<rightarrow> c!(Suc i) \<longrightarrow> (snd(c!i), snd(c!Suc i)) \<in> guar) \<and> 
   376                (fst (last c) = None \<longrightarrow> snd (last c) \<in> post)}"
   377 
   378 definition com_validity :: "'a com \<Rightarrow> 'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> 'a set \<Rightarrow> bool" 
   379                  ("\<Turnstile> _ sat [_, _, _, _]" [60,0,0,0,0] 45) where
   380   "\<Turnstile> P sat [pre, rely, guar, post] \<equiv> 
   381    \<forall>s. cp (Some P) s \<inter> assum(pre, rely) \<subseteq> comm(guar, post)"
   382 
   383 subsection {* Validity for Parallel Programs. *}
   384 
   385 definition All_None :: "(('a com) option) list \<Rightarrow> bool" where
   386   "All_None xs \<equiv> \<forall>c\<in>set xs. c=None"
   387 
   388 definition par_assum :: "('a set \<times> ('a \<times> 'a) set) \<Rightarrow> ('a par_confs) set" where
   389   "par_assum \<equiv> \<lambda>(pre, rely). {c. snd(c!0) \<in> pre \<and> (\<forall>i. Suc i<length c \<longrightarrow> 
   390              c!i -pe\<rightarrow> c!Suc i \<longrightarrow> (snd(c!i), snd(c!Suc i)) \<in> rely)}"
   391 
   392 definition par_comm :: "(('a \<times> 'a) set \<times> 'a set) \<Rightarrow> ('a par_confs) set" where
   393   "par_comm \<equiv> \<lambda>(guar, post). {c. (\<forall>i. Suc i<length c \<longrightarrow>   
   394         c!i -pc\<rightarrow> c!Suc i \<longrightarrow> (snd(c!i), snd(c!Suc i)) \<in> guar) \<and> 
   395          (All_None (fst (last c)) \<longrightarrow> snd( last c) \<in> post)}"
   396 
   397 definition par_com_validity :: "'a  par_com \<Rightarrow> 'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set 
   398 \<Rightarrow> 'a set \<Rightarrow> bool"  ("\<Turnstile> _ SAT [_, _, _, _]" [60,0,0,0,0] 45) where
   399   "\<Turnstile> Ps SAT [pre, rely, guar, post] \<equiv> 
   400    \<forall>s. par_cp Ps s \<inter> par_assum(pre, rely) \<subseteq> par_comm(guar, post)"
   401 
   402 subsection {* Compositionality of the Semantics *}
   403 
   404 subsubsection {* Definition of the conjoin operator *}
   405 
   406 definition same_length :: "'a par_confs \<Rightarrow> ('a confs) list \<Rightarrow> bool" where
   407   "same_length c clist \<equiv> (\<forall>i<length clist. length(clist!i)=length c)"
   408  
   409 definition same_state :: "'a par_confs \<Rightarrow> ('a confs) list \<Rightarrow> bool" where
   410   "same_state c clist \<equiv> (\<forall>i <length clist. \<forall>j<length c. snd(c!j) = snd((clist!i)!j))"
   411 
   412 definition same_program :: "'a par_confs \<Rightarrow> ('a confs) list \<Rightarrow> bool" where
   413   "same_program c clist \<equiv> (\<forall>j<length c. fst(c!j) = map (\<lambda>x. fst(nth x j)) clist)"
   414 
   415 definition compat_label :: "'a par_confs \<Rightarrow> ('a confs) list \<Rightarrow> bool" where
   416   "compat_label c clist \<equiv> (\<forall>j. Suc j<length c \<longrightarrow> 
   417          (c!j -pc\<rightarrow> c!Suc j \<and> (\<exists>i<length clist. (clist!i)!j -c\<rightarrow> (clist!i)! Suc j \<and> 
   418                        (\<forall>l<length clist. l\<noteq>i \<longrightarrow> (clist!l)!j -e\<rightarrow> (clist!l)! Suc j))) \<or> 
   419          (c!j -pe\<rightarrow> c!Suc j \<and> (\<forall>i<length clist. (clist!i)!j -e\<rightarrow> (clist!i)! Suc j)))"
   420 
   421 definition conjoin :: "'a par_confs \<Rightarrow> ('a confs) list \<Rightarrow> bool"  ("_ \<propto> _" [65,65] 64) where
   422   "c \<propto> clist \<equiv> (same_length c clist) \<and> (same_state c clist) \<and> (same_program c clist) \<and> (compat_label c clist)"
   423 
   424 subsubsection {* Some previous lemmas *}
   425 
   426 lemma list_eq_if [rule_format]: 
   427   "\<forall>ys. xs=ys \<longrightarrow> (length xs = length ys) \<longrightarrow> (\<forall>i<length xs. xs!i=ys!i)"
   428 apply (induct xs)
   429  apply simp
   430 apply clarify
   431 done
   432 
   433 lemma list_eq: "(length xs = length ys \<and> (\<forall>i<length xs. xs!i=ys!i)) = (xs=ys)"
   434 apply(rule iffI)
   435  apply clarify
   436  apply(erule nth_equalityI)
   437  apply simp+
   438 done
   439 
   440 lemma nth_tl: "\<lbrakk> ys!0=a; ys\<noteq>[] \<rbrakk> \<Longrightarrow> ys=(a#(tl ys))"
   441 apply(case_tac ys)
   442  apply simp+
   443 done
   444 
   445 lemma nth_tl_if [rule_format]: "ys\<noteq>[] \<longrightarrow> ys!0=a \<longrightarrow> P ys \<longrightarrow> P (a#(tl ys))"
   446 apply(induct ys)
   447  apply simp+
   448 done
   449 
   450 lemma nth_tl_onlyif [rule_format]: "ys\<noteq>[] \<longrightarrow> ys!0=a \<longrightarrow> P (a#(tl ys)) \<longrightarrow> P ys"
   451 apply(induct ys)
   452  apply simp+
   453 done
   454 
   455 lemma seq_not_eq1: "Seq c1 c2\<noteq>c1"
   456 apply(rule com.induct)
   457 apply simp_all
   458 apply clarify
   459 done
   460 
   461 lemma seq_not_eq2: "Seq c1 c2\<noteq>c2"
   462 apply(rule com.induct)
   463 apply simp_all
   464 apply clarify
   465 done
   466 
   467 lemma if_not_eq1: "Cond b c1 c2 \<noteq>c1"
   468 apply(rule com.induct)
   469 apply simp_all
   470 apply clarify
   471 done
   472 
   473 lemma if_not_eq2: "Cond b c1 c2\<noteq>c2"
   474 apply(rule com.induct)
   475 apply simp_all
   476 apply clarify
   477 done
   478 
   479 lemmas seq_and_if_not_eq [simp] = seq_not_eq1 seq_not_eq2 
   480 seq_not_eq1 [THEN not_sym] seq_not_eq2 [THEN not_sym] 
   481 if_not_eq1 if_not_eq2 if_not_eq1 [THEN not_sym] if_not_eq2 [THEN not_sym]
   482 
   483 lemma prog_not_eq_in_ctran_aux:
   484   assumes c: "(P,s) -c\<rightarrow> (Q,t)"
   485   shows "P\<noteq>Q" using c
   486   by (induct x1 \<equiv> "(P,s)" x2 \<equiv> "(Q,t)" arbitrary: P s Q t) auto
   487 
   488 lemma prog_not_eq_in_ctran [simp]: "\<not> (P,s) -c\<rightarrow> (P,t)"
   489 apply clarify
   490 apply(drule prog_not_eq_in_ctran_aux)
   491 apply simp
   492 done
   493 
   494 lemma prog_not_eq_in_par_ctran_aux [rule_format]: "(P,s) -pc\<rightarrow> (Q,t) \<Longrightarrow> (P\<noteq>Q)"
   495 apply(erule par_ctran.induct)
   496 apply(drule prog_not_eq_in_ctran_aux)
   497 apply clarify
   498 apply(drule list_eq_if)
   499  apply simp_all
   500 apply force
   501 done
   502 
   503 lemma prog_not_eq_in_par_ctran [simp]: "\<not> (P,s) -pc\<rightarrow> (P,t)"
   504 apply clarify
   505 apply(drule prog_not_eq_in_par_ctran_aux)
   506 apply simp
   507 done
   508 
   509 lemma tl_in_cptn: "\<lbrakk> a#xs \<in>cptn; xs\<noteq>[] \<rbrakk> \<Longrightarrow> xs\<in>cptn"
   510 apply(force elim:cptn.cases)
   511 done
   512 
   513 lemma tl_zero[rule_format]: 
   514   "P (ys!Suc j) \<longrightarrow> Suc j<length ys \<longrightarrow> ys\<noteq>[] \<longrightarrow> P (tl(ys)!j)"
   515 apply(induct ys)
   516  apply simp_all
   517 done
   518 
   519 subsection {* The Semantics is Compositional *}
   520 
   521 lemma aux_if [rule_format]: 
   522   "\<forall>xs s clist. (length clist = length xs \<and> (\<forall>i<length xs. (xs!i,s)#clist!i \<in> cptn) 
   523   \<and> ((xs, s)#ys \<propto> map (\<lambda>i. (fst i,s)#snd i) (zip xs clist)) 
   524    \<longrightarrow> (xs, s)#ys \<in> par_cptn)"
   525 apply(induct ys)
   526  apply(clarify)
   527  apply(rule ParCptnOne)
   528 apply(clarify)
   529 apply(simp add:conjoin_def compat_label_def)
   530 apply clarify
   531 apply(erule_tac x="0" and P="\<lambda>j. ?H j \<longrightarrow> (?P j \<or> ?Q j)" in all_dupE,simp)
   532 apply(erule disjE)
   533 --{* first step is a Component step *}
   534  apply clarify 
   535  apply simp
   536  apply(subgoal_tac "a=(xs[i:=(fst(clist!i!0))])")
   537   apply(subgoal_tac "b=snd(clist!i!0)",simp)
   538    prefer 2
   539    apply(simp add: same_state_def)
   540    apply(erule_tac x=i in allE,erule impE,assumption, 
   541          erule_tac x=1 and P="\<lambda>j. (?H j) \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   542   prefer 2
   543   apply(simp add:same_program_def)
   544   apply(erule_tac x=1 and P="\<lambda>j. ?H j \<longrightarrow> (fst (?s j))=(?t j)" in allE,simp)
   545   apply(rule nth_equalityI,simp)
   546   apply clarify
   547   apply(case_tac "i=ia",simp,simp)
   548   apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE)
   549   apply(drule_tac t=i in not_sym,simp)
   550   apply(erule etranE,simp)
   551  apply(rule ParCptnComp)
   552   apply(erule ParComp,simp)
   553 --{* applying the induction hypothesis *}
   554  apply(erule_tac x="xs[i := fst (clist ! i ! 0)]" in allE)
   555  apply(erule_tac x="snd (clist ! i ! 0)" in allE)
   556  apply(erule mp)
   557  apply(rule_tac x="map tl clist" in exI,simp)
   558  apply(rule conjI,clarify)
   559   apply(case_tac "i=ia",simp)
   560    apply(rule nth_tl_if)
   561      apply(force simp add:same_length_def length_Suc_conv)
   562     apply simp
   563    apply(erule allE,erule impE,assumption,erule tl_in_cptn)
   564    apply(force simp add:same_length_def length_Suc_conv)
   565   apply(rule nth_tl_if)
   566     apply(force simp add:same_length_def length_Suc_conv)
   567    apply(simp add:same_state_def)
   568    apply(erule_tac x=ia in allE, erule impE, assumption, 
   569      erule_tac x=1 and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE)
   570    apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE)
   571    apply(drule_tac t=i  in not_sym,simp)
   572    apply(erule etranE,simp)
   573   apply(erule allE,erule impE,assumption,erule tl_in_cptn)
   574   apply(force simp add:same_length_def length_Suc_conv)
   575  apply(simp add:same_length_def same_state_def)
   576  apply(rule conjI)
   577   apply clarify
   578   apply(case_tac j,simp,simp)
   579   apply(erule_tac x=ia in allE, erule impE, assumption,
   580         erule_tac x="Suc(Suc nat)" and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   581   apply(force simp add:same_length_def length_Suc_conv)
   582  apply(rule conjI)
   583   apply(simp add:same_program_def)
   584   apply clarify
   585   apply(case_tac j,simp)
   586    apply(rule nth_equalityI,simp)
   587    apply clarify
   588    apply(case_tac "i=ia",simp,simp)
   589   apply(erule_tac x="Suc(Suc nat)" and P="\<lambda>j. ?H j \<longrightarrow> (fst (?s j))=(?t j)" in allE,simp)
   590   apply(rule nth_equalityI,simp,simp)
   591   apply(force simp add:length_Suc_conv)
   592  apply(rule allI,rule impI)
   593  apply(erule_tac x="Suc j" and P="\<lambda>j. ?H j \<longrightarrow> (?I j \<or> ?J j)" in allE,simp)
   594  apply(erule disjE) 
   595   apply clarify
   596   apply(rule_tac x=ia in exI,simp)
   597   apply(case_tac "i=ia",simp)
   598    apply(rule conjI)
   599     apply(force simp add: length_Suc_conv)
   600    apply clarify
   601    apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE,erule impE,assumption)
   602    apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE,erule impE,assumption)
   603    apply simp
   604    apply(case_tac j,simp)
   605     apply(rule tl_zero)
   606       apply(erule_tac x=l in allE, erule impE, assumption, 
   607             erule_tac x=1 and P="\<lambda>j.  (?H j) \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   608       apply(force elim:etranE intro:Env)
   609      apply force
   610     apply force
   611    apply simp
   612    apply(rule tl_zero)
   613      apply(erule tl_zero)
   614       apply force
   615      apply force
   616     apply force
   617    apply force
   618   apply(rule conjI,simp)
   619    apply(rule nth_tl_if)
   620      apply force
   621     apply(erule_tac x=ia  in allE, erule impE, assumption,
   622           erule_tac x=1 and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE)
   623     apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE)
   624     apply(drule_tac t=i  in not_sym,simp)
   625     apply(erule etranE,simp)
   626    apply(erule tl_zero)
   627     apply force
   628    apply force
   629   apply clarify
   630   apply(case_tac "i=l",simp)
   631    apply(rule nth_tl_if)
   632      apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   633     apply simp
   634    apply(erule_tac P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE,erule impE,assumption,erule impE,assumption)
   635    apply(erule tl_zero,force)
   636    apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   637    apply(rule nth_tl_if)
   638      apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   639     apply(erule_tac x=l  in allE, erule impE, assumption,
   640           erule_tac x=1 and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE)
   641     apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE,erule impE, assumption,simp)
   642     apply(erule etranE,simp)
   643    apply(rule tl_zero)
   644     apply force
   645    apply force
   646   apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   647  apply(rule disjI2)
   648  apply(case_tac j,simp)
   649   apply clarify
   650   apply(rule tl_zero)
   651     apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> ?I j\<in>etran" in allE,erule impE, assumption)
   652     apply(case_tac "i=ia",simp,simp)
   653     apply(erule_tac x=ia  in allE, erule impE, assumption,
   654     erule_tac x=1 and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE)
   655     apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE,erule impE, assumption,simp)
   656     apply(force elim:etranE intro:Env)
   657    apply force
   658   apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   659  apply simp
   660  apply clarify
   661  apply(rule tl_zero)
   662    apply(rule tl_zero,force)
   663     apply force
   664    apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   665   apply force
   666  apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   667 --{* first step is an environmental step *}
   668 apply clarify
   669 apply(erule par_etran.cases)
   670 apply simp
   671 apply(rule ParCptnEnv)
   672 apply(erule_tac x="Ps" in allE)
   673 apply(erule_tac x="t" in allE)
   674 apply(erule mp)
   675 apply(rule_tac x="map tl clist" in exI,simp)
   676 apply(rule conjI)
   677  apply clarify
   678  apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (?I ?s j) \<in> cptn" in allE,simp)
   679  apply(erule cptn.cases)
   680    apply(simp add:same_length_def)
   681    apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   682   apply(simp add:same_state_def)
   683   apply(erule_tac x=i  in allE, erule impE, assumption,
   684    erule_tac x=1 and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   685  apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> ?J j \<in>etran" in allE,simp)
   686  apply(erule etranE,simp)
   687 apply(simp add:same_state_def same_length_def)
   688 apply(rule conjI,clarify)
   689  apply(case_tac j,simp,simp)
   690  apply(erule_tac x=i  in allE, erule impE, assumption,
   691        erule_tac x="Suc(Suc nat)" and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   692  apply(rule tl_zero)
   693    apply(simp)
   694   apply force
   695  apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   696 apply(rule conjI)
   697  apply(simp add:same_program_def)
   698  apply clarify
   699  apply(case_tac j,simp)
   700   apply(rule nth_equalityI,simp)
   701   apply clarify
   702   apply simp
   703  apply(erule_tac x="Suc(Suc nat)" and P="\<lambda>j. ?H j \<longrightarrow> (fst (?s j))=(?t j)" in allE,simp)
   704  apply(rule nth_equalityI,simp,simp)
   705  apply(force simp add:length_Suc_conv)
   706 apply(rule allI,rule impI)
   707 apply(erule_tac x="Suc j" and P="\<lambda>j. ?H j \<longrightarrow> (?I j \<or> ?J j)" in allE,simp)
   708 apply(erule disjE) 
   709  apply clarify
   710  apply(rule_tac x=i in exI,simp)
   711  apply(rule conjI)
   712   apply(erule_tac x=i and P="\<lambda>i. ?H i \<longrightarrow> ?J i \<in>etran" in allE, erule impE, assumption)
   713   apply(erule etranE,simp)
   714   apply(erule_tac x=i  in allE, erule impE, assumption,
   715         erule_tac x=1 and P="\<lambda>j.  (?H j) \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   716   apply(rule nth_tl_if)
   717    apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   718   apply simp
   719  apply(erule tl_zero,force) 
   720   apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   721  apply clarify
   722  apply(erule_tac x=l and P="\<lambda>i. ?H i \<longrightarrow> ?J i \<in>etran" in allE, erule impE, assumption)
   723  apply(erule etranE,simp)
   724  apply(erule_tac x=l  in allE, erule impE, assumption,
   725        erule_tac x=1 and P="\<lambda>j.  (?H j) \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   726  apply(rule nth_tl_if)
   727    apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   728   apply simp
   729   apply(rule tl_zero,force)
   730   apply force
   731  apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   732 apply(rule disjI2)
   733 apply simp
   734 apply clarify
   735 apply(case_tac j,simp)
   736  apply(rule tl_zero)
   737    apply(erule_tac x=i and P="\<lambda>i. ?H i \<longrightarrow> ?J i \<in>etran" in allE, erule impE, assumption)
   738    apply(erule_tac x=i and P="\<lambda>i. ?H i \<longrightarrow> ?J i \<in>etran" in allE, erule impE, assumption)
   739    apply(force elim:etranE intro:Env)
   740   apply force
   741  apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   742 apply simp
   743 apply(rule tl_zero)
   744   apply(rule tl_zero,force)
   745    apply force
   746   apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   747  apply force
   748 apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
   749 done
   750 
   751 lemma less_Suc_0 [iff]: "(n < Suc 0) = (n = 0)"
   752 by auto
   753 
   754 lemma aux_onlyif [rule_format]: "\<forall>xs s. (xs, s)#ys \<in> par_cptn \<longrightarrow> 
   755   (\<exists>clist. (length clist = length xs) \<and> 
   756   (xs, s)#ys \<propto> map (\<lambda>i. (fst i,s)#(snd i)) (zip xs clist) \<and> 
   757   (\<forall>i<length xs. (xs!i,s)#(clist!i) \<in> cptn))"
   758 apply(induct ys)
   759  apply(clarify)
   760  apply(rule_tac x="map (\<lambda>i. []) [0..<length xs]" in exI)
   761  apply(simp add: conjoin_def same_length_def same_state_def same_program_def compat_label_def)
   762  apply(rule conjI)
   763   apply(rule nth_equalityI,simp,simp)
   764  apply(force intro: cptn.intros)
   765 apply(clarify)
   766 apply(erule par_cptn.cases,simp)
   767  apply simp
   768  apply(erule_tac x="xs" in allE)
   769  apply(erule_tac x="t" in allE,simp)
   770  apply clarify
   771  apply(rule_tac x="(map (\<lambda>j. (P!j, t)#(clist!j)) [0..<length P])" in exI,simp)
   772  apply(rule conjI)
   773   prefer 2
   774   apply clarify
   775   apply(rule CptnEnv,simp)
   776  apply(simp add:conjoin_def same_length_def same_state_def)
   777  apply (rule conjI)
   778   apply clarify
   779   apply(case_tac j,simp,simp)
   780  apply(rule conjI)
   781   apply(simp add:same_program_def)
   782   apply clarify
   783   apply(case_tac j,simp)
   784    apply(rule nth_equalityI,simp,simp)
   785   apply simp
   786   apply(rule nth_equalityI,simp,simp)
   787  apply(simp add:compat_label_def)
   788  apply clarify
   789  apply(case_tac j,simp)
   790   apply(simp add:ParEnv)
   791   apply clarify
   792   apply(simp add:Env)
   793  apply simp
   794  apply(erule_tac x=nat in allE,erule impE, assumption)
   795  apply(erule disjE,simp)
   796   apply clarify
   797   apply(rule_tac x=i in exI,simp)
   798  apply force
   799 apply(erule par_ctran.cases,simp)
   800 apply(erule_tac x="Ps[i:=r]" in allE)
   801 apply(erule_tac x="ta" in allE,simp)
   802 apply clarify
   803 apply(rule_tac x="(map (\<lambda>j. (Ps!j, ta)#(clist!j)) [0..<length Ps]) [i:=((r, ta)#(clist!i))]" in exI,simp)
   804 apply(rule conjI)
   805  prefer 2
   806  apply clarify
   807  apply(case_tac "i=ia",simp)
   808   apply(erule CptnComp)
   809   apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> (?I j \<in> cptn)" in allE,simp)
   810  apply simp
   811  apply(erule_tac x=ia in allE)
   812  apply(rule CptnEnv,simp)
   813 apply(simp add:conjoin_def)
   814 apply (rule conjI)
   815  apply(simp add:same_length_def)
   816  apply clarify
   817  apply(case_tac "i=ia",simp,simp)
   818 apply(rule conjI)
   819  apply(simp add:same_state_def)
   820  apply clarify
   821  apply(case_tac j, simp, simp (no_asm_simp))
   822  apply(case_tac "i=ia",simp,simp)
   823 apply(rule conjI)
   824  apply(simp add:same_program_def)
   825  apply clarify
   826  apply(case_tac j,simp)
   827   apply(rule nth_equalityI,simp,simp)
   828  apply simp
   829  apply(rule nth_equalityI,simp,simp)
   830  apply(erule_tac x=nat and P="\<lambda>j. ?H j \<longrightarrow> (fst (?a j))=((?b j))" in allE)
   831  apply(case_tac nat)
   832   apply clarify
   833   apply(case_tac "i=ia",simp,simp)
   834  apply clarify
   835  apply(case_tac "i=ia",simp,simp)
   836 apply(simp add:compat_label_def)
   837 apply clarify
   838 apply(case_tac j)
   839  apply(rule conjI,simp)
   840   apply(erule ParComp,assumption)
   841   apply clarify
   842   apply(rule_tac x=i in exI,simp)
   843  apply clarify
   844  apply(rule Env)
   845 apply simp
   846 apply(erule_tac x=nat and P="\<lambda>j. ?H j \<longrightarrow> (?P j \<or> ?Q j)" in allE,simp)
   847 apply(erule disjE)
   848  apply clarify
   849  apply(rule_tac x=ia in exI,simp)
   850  apply(rule conjI)
   851   apply(case_tac "i=ia",simp,simp)
   852  apply clarify
   853  apply(case_tac "i=l",simp)
   854   apply(case_tac "l=ia",simp,simp)
   855   apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)
   856  apply simp
   857  apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)
   858 apply clarify
   859 apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> (?P j)\<in>etran" in allE, erule impE, assumption)
   860 apply(case_tac "i=ia",simp,simp)
   861 done
   862 
   863 lemma one_iff_aux: "xs\<noteq>[] \<Longrightarrow> (\<forall>ys. ((xs, s)#ys \<in> par_cptn) = 
   864  (\<exists>clist. length clist= length xs \<and> 
   865  ((xs, s)#ys \<propto> map (\<lambda>i. (fst i,s)#(snd i)) (zip xs clist)) \<and> 
   866  (\<forall>i<length xs. (xs!i,s)#(clist!i) \<in> cptn))) = 
   867  (par_cp (xs) s = {c. \<exists>clist. (length clist)=(length xs) \<and>
   868  (\<forall>i<length clist. (clist!i) \<in> cp(xs!i) s) \<and> c \<propto> clist})" 
   869 apply (rule iffI)
   870  apply(rule subset_antisym)
   871   apply(rule subsetI) 
   872   apply(clarify)
   873   apply(simp add:par_cp_def cp_def)
   874   apply(case_tac x)
   875    apply(force elim:par_cptn.cases)
   876   apply simp
   877   apply(erule_tac x="list" in allE)
   878   apply clarify
   879   apply simp
   880   apply(rule_tac x="map (\<lambda>i. (fst i, s) # snd i) (zip xs clist)" in exI,simp)
   881  apply(rule subsetI) 
   882  apply(clarify)
   883  apply(case_tac x)
   884   apply(erule_tac x=0 in allE)
   885   apply(simp add:cp_def conjoin_def same_length_def same_program_def same_state_def compat_label_def)
   886   apply clarify
   887   apply(erule cptn.cases,force,force,force)
   888  apply(simp add:par_cp_def conjoin_def  same_length_def same_program_def same_state_def compat_label_def)
   889  apply clarify
   890  apply(erule_tac x=0 and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in all_dupE)
   891  apply(subgoal_tac "a = xs")
   892   apply(subgoal_tac "b = s",simp)
   893    prefer 3
   894    apply(erule_tac x=0 and P="\<lambda>j. ?H j \<longrightarrow> (fst (?s j))=((?t j))" in allE)
   895    apply (simp add:cp_def)
   896    apply(rule nth_equalityI,simp,simp)
   897   prefer 2
   898   apply(erule_tac x=0 in allE)
   899   apply (simp add:cp_def)
   900   apply(erule_tac x=0 and P="\<lambda>j. ?H j \<longrightarrow> (\<forall>i. ?T i \<longrightarrow> (snd (?d j i))=(snd (?e j i)))" in allE,simp)
   901   apply(erule_tac x=0 and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   902  apply(erule_tac x=list in allE)
   903  apply(rule_tac x="map tl clist" in exI,simp) 
   904  apply(rule conjI)
   905   apply clarify
   906   apply(case_tac j,simp)
   907    apply(erule_tac x=i  in allE, erule impE, assumption,
   908         erule_tac x="0" and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
   909   apply(erule_tac x=i  in allE, erule impE, assumption,
   910         erule_tac x="Suc nat" and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE)
   911   apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   912   apply(case_tac "clist!i",simp,simp)
   913  apply(rule conjI)
   914   apply clarify
   915   apply(rule nth_equalityI,simp,simp)
   916   apply(case_tac j)
   917    apply clarify
   918    apply(erule_tac x=i in allE)
   919    apply(simp add:cp_def)
   920   apply clarify
   921   apply simp
   922   apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   923   apply(case_tac "clist!i",simp,simp)
   924  apply(thin_tac "?H = (\<exists>i. ?J i)")
   925  apply(rule conjI)
   926   apply clarify
   927   apply(erule_tac x=j in allE,erule impE, assumption,erule disjE)
   928    apply clarify
   929    apply(rule_tac x=i in exI,simp)
   930    apply(case_tac j,simp)
   931     apply(rule conjI)
   932      apply(erule_tac x=i in allE)
   933      apply(simp add:cp_def)
   934      apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   935      apply(case_tac "clist!i",simp,simp)
   936     apply clarify
   937     apply(erule_tac x=l in allE)
   938     apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE)
   939     apply clarify
   940     apply(simp add:cp_def)
   941     apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   942     apply(case_tac "clist!l",simp,simp)
   943    apply simp
   944    apply(rule conjI)
   945     apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   946     apply(case_tac "clist!i",simp,simp)
   947    apply clarify
   948    apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE)
   949    apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   950    apply(case_tac "clist!l",simp,simp)
   951   apply clarify
   952   apply(erule_tac x=i in allE)
   953   apply(simp add:cp_def)
   954   apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   955   apply(case_tac "clist!i",simp)
   956   apply(rule nth_tl_if,simp,simp)
   957   apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (?P j)\<in>etran" in allE, erule impE, assumption,simp)
   958   apply(simp add:cp_def)
   959   apply clarify
   960   apply(rule nth_tl_if)
   961    apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   962    apply(case_tac "clist!i",simp,simp)
   963   apply force
   964  apply force
   965 apply clarify
   966 apply(rule iffI)
   967  apply(simp add:par_cp_def)
   968  apply(erule_tac c="(xs, s) # ys" in equalityCE)
   969   apply simp
   970   apply clarify
   971   apply(rule_tac x="map tl clist" in exI)
   972   apply simp
   973   apply (rule conjI)
   974    apply(simp add:conjoin_def cp_def)
   975    apply(rule conjI)
   976     apply clarify
   977     apply(unfold same_length_def)
   978     apply clarify
   979     apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,simp)
   980    apply(rule conjI)
   981     apply(simp add:same_state_def)
   982     apply clarify
   983     apply(erule_tac x=i in allE, erule impE, assumption,
   984        erule_tac x=j and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE)
   985     apply(case_tac j,simp)
   986     apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   987     apply(case_tac "clist!i",simp,simp)
   988    apply(rule conjI)
   989     apply(simp add:same_program_def)
   990     apply clarify
   991     apply(rule nth_equalityI,simp,simp)
   992     apply(case_tac j,simp)
   993     apply clarify
   994     apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
   995     apply(case_tac "clist!i",simp,simp)
   996    apply clarify
   997    apply(simp add:compat_label_def)
   998    apply(rule allI,rule impI)
   999    apply(erule_tac x=j in allE,erule impE, assumption)
  1000    apply(erule disjE)
  1001     apply clarify
  1002     apply(rule_tac x=i in exI,simp)
  1003     apply(rule conjI)
  1004      apply(erule_tac x=i in allE)
  1005      apply(case_tac j,simp)
  1006       apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
  1007       apply(case_tac "clist!i",simp,simp)
  1008      apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
  1009      apply(case_tac "clist!i",simp,simp)
  1010     apply clarify
  1011     apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> ?I j \<longrightarrow> ?J j" in allE)
  1012     apply(erule_tac x=l and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE)
  1013     apply(case_tac "clist!l",simp,simp)
  1014     apply(erule_tac x=l in allE,simp)
  1015    apply(rule disjI2)
  1016    apply clarify
  1017    apply(rule tl_zero)
  1018      apply(case_tac j,simp,simp)
  1019      apply(rule tl_zero,force)   
  1020       apply force
  1021      apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
  1022     apply force
  1023    apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (length (?s j) = ?t)" in allE,force)
  1024   apply clarify
  1025   apply(erule_tac x=i in allE)
  1026   apply(simp add:cp_def)
  1027   apply(rule nth_tl_if)
  1028     apply(simp add:conjoin_def)
  1029     apply clarify
  1030     apply(simp add:same_length_def)
  1031     apply(erule_tac x=i in allE,simp)
  1032    apply simp
  1033   apply simp
  1034  apply simp
  1035 apply clarify
  1036 apply(erule_tac c="(xs, s) # ys" in equalityCE)
  1037  apply(simp add:par_cp_def)
  1038 apply simp
  1039 apply(erule_tac x="map (\<lambda>i. (fst i, s) # snd i) (zip xs clist)" in allE)
  1040 apply simp
  1041 apply clarify
  1042 apply(simp add:cp_def)
  1043 done
  1044 
  1045 theorem one: "xs\<noteq>[] \<Longrightarrow> 
  1046  par_cp xs s = {c. \<exists>clist. (length clist)=(length xs) \<and> 
  1047                (\<forall>i<length clist. (clist!i) \<in> cp(xs!i) s) \<and> c \<propto> clist}"
  1048 apply(frule one_iff_aux)
  1049 apply(drule sym)
  1050 apply(erule iffD2)
  1051 apply clarify
  1052 apply(rule iffI)
  1053  apply(erule aux_onlyif)
  1054 apply clarify
  1055 apply(force intro:aux_if)
  1056 done
  1057 
  1058 end