src/HOL/Hoare_Parallel/OG_Hoare.thy
author huffman
Wed Sep 08 16:10:49 2010 -0700 (2010-09-08)
changeset 44535 5e681762d538
parent 39246 9e58f0499f57
child 46008 c296c75f4cf4
permissions -rw-r--r--
use rename_tac to make proof script more robust (with separate set type, 'clarify' yields different variable names)
     1 
     2 header {* \section{The Proof System} *}
     3 
     4 theory OG_Hoare imports OG_Tran begin
     5 
     6 primrec assertions :: "'a ann_com \<Rightarrow> ('a assn) set" where
     7   "assertions (AnnBasic r f) = {r}"
     8 | "assertions (AnnSeq c1 c2) = assertions c1 \<union> assertions c2"
     9 | "assertions (AnnCond1 r b c1 c2) = {r} \<union> assertions c1 \<union> assertions c2"
    10 | "assertions (AnnCond2 r b c) = {r} \<union> assertions c"
    11 | "assertions (AnnWhile r b i c) = {r, i} \<union> assertions c"
    12 | "assertions (AnnAwait r b c) = {r}" 
    13 
    14 primrec atomics :: "'a ann_com \<Rightarrow> ('a assn \<times> 'a com) set" where
    15   "atomics (AnnBasic r f) = {(r, Basic f)}"
    16 | "atomics (AnnSeq c1 c2) = atomics c1 \<union> atomics c2"
    17 | "atomics (AnnCond1 r b c1 c2) = atomics c1 \<union> atomics c2"
    18 | "atomics (AnnCond2 r b c) = atomics c"
    19 | "atomics (AnnWhile r b i c) = atomics c" 
    20 | "atomics (AnnAwait r b c) = {(r \<inter> b, c)}"
    21 
    22 primrec com :: "'a ann_triple_op \<Rightarrow> 'a ann_com_op" where
    23   "com (c, q) = c"
    24 
    25 primrec post :: "'a ann_triple_op \<Rightarrow> 'a assn" where
    26   "post (c, q) = q"
    27 
    28 definition interfree_aux :: "('a ann_com_op \<times> 'a assn \<times> 'a ann_com_op) \<Rightarrow> bool" where
    29   "interfree_aux \<equiv> \<lambda>(co, q, co'). co'= None \<or>  
    30                     (\<forall>(r,a) \<in> atomics (the co'). \<parallel>= (q \<inter> r) a q \<and>
    31                     (co = None \<or> (\<forall>p \<in> assertions (the co). \<parallel>= (p \<inter> r) a p)))"
    32 
    33 definition interfree :: "(('a ann_triple_op) list) \<Rightarrow> bool" where 
    34   "interfree Ts \<equiv> \<forall>i j. i < length Ts \<and> j < length Ts \<and> i \<noteq> j \<longrightarrow> 
    35                          interfree_aux (com (Ts!i), post (Ts!i), com (Ts!j)) "
    36 
    37 inductive
    38   oghoare :: "'a assn \<Rightarrow> 'a com \<Rightarrow> 'a assn \<Rightarrow> bool"  ("(3\<parallel>- _//_//_)" [90,55,90] 50)
    39   and ann_hoare :: "'a ann_com \<Rightarrow> 'a assn \<Rightarrow> bool"  ("(2\<turnstile> _// _)" [60,90] 45)
    40 where
    41   AnnBasic: "r \<subseteq> {s. f s \<in> q} \<Longrightarrow> \<turnstile> (AnnBasic r f) q"
    42 
    43 | AnnSeq:   "\<lbrakk> \<turnstile> c0 pre c1; \<turnstile> c1 q \<rbrakk> \<Longrightarrow> \<turnstile> (AnnSeq c0 c1) q"
    44   
    45 | AnnCond1: "\<lbrakk> r \<inter> b \<subseteq> pre c1; \<turnstile> c1 q; r \<inter> -b \<subseteq> pre c2; \<turnstile> c2 q\<rbrakk> 
    46               \<Longrightarrow> \<turnstile> (AnnCond1 r b c1 c2) q"
    47 | AnnCond2: "\<lbrakk> r \<inter> b \<subseteq> pre c; \<turnstile> c q; r \<inter> -b \<subseteq> q \<rbrakk> \<Longrightarrow> \<turnstile> (AnnCond2 r b c) q"
    48   
    49 | AnnWhile: "\<lbrakk> r \<subseteq> i; i \<inter> b \<subseteq> pre c; \<turnstile> c i; i \<inter> -b \<subseteq> q \<rbrakk> 
    50               \<Longrightarrow> \<turnstile> (AnnWhile r b i c) q"
    51   
    52 | AnnAwait:  "\<lbrakk> atom_com c; \<parallel>- (r \<inter> b) c q \<rbrakk> \<Longrightarrow> \<turnstile> (AnnAwait r b c) q"
    53   
    54 | AnnConseq: "\<lbrakk>\<turnstile> c q; q \<subseteq> q' \<rbrakk> \<Longrightarrow> \<turnstile> c q'"
    55 
    56 
    57 | Parallel: "\<lbrakk> \<forall>i<length Ts. \<exists>c q. Ts!i = (Some c, q) \<and> \<turnstile> c q; interfree Ts \<rbrakk>
    58            \<Longrightarrow> \<parallel>- (\<Inter>i\<in>{i. i<length Ts}. pre(the(com(Ts!i)))) 
    59                      Parallel Ts 
    60                   (\<Inter>i\<in>{i. i<length Ts}. post(Ts!i))"
    61 
    62 | Basic:   "\<parallel>- {s. f s \<in>q} (Basic f) q"
    63   
    64 | Seq:    "\<lbrakk> \<parallel>- p c1 r; \<parallel>- r c2 q \<rbrakk> \<Longrightarrow> \<parallel>- p (Seq c1 c2) q "
    65 
    66 | Cond:   "\<lbrakk> \<parallel>- (p \<inter> b) c1 q; \<parallel>- (p \<inter> -b) c2 q \<rbrakk> \<Longrightarrow> \<parallel>- p (Cond b c1 c2) q"
    67 
    68 | While:  "\<lbrakk> \<parallel>- (p \<inter> b) c p \<rbrakk> \<Longrightarrow> \<parallel>- p (While b i c) (p \<inter> -b)"
    69 
    70 | Conseq: "\<lbrakk> p' \<subseteq> p; \<parallel>- p c q ; q \<subseteq> q' \<rbrakk> \<Longrightarrow> \<parallel>- p' c q'"
    71 
    72 section {* Soundness *}
    73 (* In the version Isabelle-10-Sep-1999: HOL: The THEN and ELSE
    74 parts of conditional expressions (if P then x else y) are no longer
    75 simplified.  (This allows the simplifier to unfold recursive
    76 functional programs.)  To restore the old behaviour, we declare
    77 @{text "lemmas [cong del] = if_weak_cong"}. *)
    78 
    79 lemmas [cong del] = if_weak_cong
    80 
    81 lemmas ann_hoare_induct = oghoare_ann_hoare.induct [THEN conjunct2]
    82 lemmas oghoare_induct = oghoare_ann_hoare.induct [THEN conjunct1]
    83 
    84 lemmas AnnBasic = oghoare_ann_hoare.AnnBasic
    85 lemmas AnnSeq = oghoare_ann_hoare.AnnSeq
    86 lemmas AnnCond1 = oghoare_ann_hoare.AnnCond1
    87 lemmas AnnCond2 = oghoare_ann_hoare.AnnCond2
    88 lemmas AnnWhile = oghoare_ann_hoare.AnnWhile
    89 lemmas AnnAwait = oghoare_ann_hoare.AnnAwait
    90 lemmas AnnConseq = oghoare_ann_hoare.AnnConseq
    91 
    92 lemmas Parallel = oghoare_ann_hoare.Parallel
    93 lemmas Basic = oghoare_ann_hoare.Basic
    94 lemmas Seq = oghoare_ann_hoare.Seq
    95 lemmas Cond = oghoare_ann_hoare.Cond
    96 lemmas While = oghoare_ann_hoare.While
    97 lemmas Conseq = oghoare_ann_hoare.Conseq
    98 
    99 subsection {* Soundness of the System for Atomic Programs *}
   100 
   101 lemma Basic_ntran [rule_format]: 
   102  "(Basic f, s) -Pn\<rightarrow> (Parallel Ts, t) \<longrightarrow> All_None Ts \<longrightarrow> t = f s"
   103 apply(induct "n")
   104  apply(simp (no_asm))
   105 apply(fast dest: rel_pow_Suc_D2 Parallel_empty_lemma elim: transition_cases)
   106 done
   107 
   108 lemma SEM_fwhile: "SEM S (p \<inter> b) \<subseteq> p \<Longrightarrow> SEM (fwhile b S k) p \<subseteq> (p \<inter> -b)"
   109 apply (induct "k")
   110  apply(simp (no_asm) add: L3_5v_lemma3)
   111 apply(simp (no_asm) add: L3_5iv L3_5ii Parallel_empty)
   112 apply(rule conjI)
   113  apply (blast dest: L3_5i) 
   114 apply(simp add: SEM_def sem_def id_def)
   115 apply (blast dest: Basic_ntran rtrancl_imp_UN_rel_pow) 
   116 done
   117 
   118 lemma atom_hoare_sound [rule_format]: 
   119  " \<parallel>- p c q \<longrightarrow> atom_com(c) \<longrightarrow> \<parallel>= p c q"
   120 apply (unfold com_validity_def)
   121 apply(rule oghoare_induct)
   122 apply simp_all
   123 --{*Basic*}
   124     apply(simp add: SEM_def sem_def)
   125     apply(fast dest: rtrancl_imp_UN_rel_pow Basic_ntran)
   126 --{* Seq *}
   127    apply(rule impI)
   128    apply(rule subset_trans)
   129     prefer 2 apply simp
   130    apply(simp add: L3_5ii L3_5i)
   131 --{* Cond *}
   132   apply(simp add: L3_5iv)
   133 --{* While *}
   134  apply (force simp add: L3_5v dest: SEM_fwhile) 
   135 --{* Conseq *}
   136 apply(force simp add: SEM_def sem_def)
   137 done
   138     
   139 subsection {* Soundness of the System for Component Programs *}
   140 
   141 inductive_cases ann_transition_cases:
   142     "(None,s) -1\<rightarrow> (c', s')"
   143     "(Some (AnnBasic r f),s) -1\<rightarrow> (c', s')"
   144     "(Some (AnnSeq c1 c2), s) -1\<rightarrow> (c', s')"
   145     "(Some (AnnCond1 r b c1 c2), s) -1\<rightarrow> (c', s')"
   146     "(Some (AnnCond2 r b c), s) -1\<rightarrow> (c', s')"
   147     "(Some (AnnWhile r b I c), s) -1\<rightarrow> (c', s')"
   148     "(Some (AnnAwait r b c),s) -1\<rightarrow> (c', s')"
   149 
   150 text {* Strong Soundness for Component Programs:*}
   151 
   152 lemma ann_hoare_case_analysis [rule_format]: 
   153   defines I: "I \<equiv> \<lambda>C q'.
   154   ((\<forall>r f. C = AnnBasic r f \<longrightarrow> (\<exists>q. r \<subseteq> {s. f s \<in> q} \<and> q \<subseteq> q')) \<and>  
   155   (\<forall>c0 c1. C = AnnSeq c0 c1 \<longrightarrow> (\<exists>q. q \<subseteq> q' \<and> \<turnstile> c0 pre c1 \<and> \<turnstile> c1 q)) \<and>  
   156   (\<forall>r b c1 c2. C = AnnCond1 r b c1 c2 \<longrightarrow> (\<exists>q. q \<subseteq> q' \<and>  
   157   r \<inter> b \<subseteq> pre c1 \<and> \<turnstile> c1 q \<and> r \<inter> -b \<subseteq> pre c2 \<and> \<turnstile> c2 q)) \<and>  
   158   (\<forall>r b c. C = AnnCond2 r b c \<longrightarrow> 
   159   (\<exists>q. q \<subseteq> q' \<and> r \<inter> b \<subseteq> pre c  \<and> \<turnstile> c q \<and> r \<inter> -b \<subseteq> q)) \<and>  
   160   (\<forall>r i b c. C = AnnWhile r b i c \<longrightarrow>  
   161   (\<exists>q. q \<subseteq> q' \<and> r \<subseteq> i \<and> i \<inter> b \<subseteq> pre c \<and> \<turnstile> c i \<and> i \<inter> -b \<subseteq> q)) \<and>  
   162   (\<forall>r b c. C = AnnAwait r b c \<longrightarrow> (\<exists>q. q \<subseteq> q' \<and> \<parallel>- (r \<inter> b) c q)))"
   163   shows "\<turnstile> C q' \<longrightarrow> I C q'"
   164 apply(rule ann_hoare_induct)
   165 apply (simp_all add: I)
   166  apply(rule_tac x=q in exI,simp)+
   167 apply(rule conjI,clarify,simp,clarify,rule_tac x=qa in exI,fast)+
   168 apply(clarify,simp,clarify,rule_tac x=qa in exI,fast)
   169 done
   170 
   171 lemma Help: "(transition \<inter> {(x,y). True}) = (transition)"
   172 apply force
   173 done
   174 
   175 lemma Strong_Soundness_aux_aux [rule_format]: 
   176  "(co, s) -1\<rightarrow> (co', t) \<longrightarrow> (\<forall>c. co = Some c \<longrightarrow> s\<in> pre c \<longrightarrow> 
   177  (\<forall>q. \<turnstile> c q \<longrightarrow> (if co' = None then t\<in>q else t \<in> pre(the co') \<and> \<turnstile> (the co') q )))"
   178 apply(rule ann_transition_transition.induct [THEN conjunct1])
   179 apply simp_all 
   180 --{* Basic *}
   181          apply clarify
   182          apply(frule ann_hoare_case_analysis)
   183          apply force
   184 --{* Seq *}
   185         apply clarify
   186         apply(frule ann_hoare_case_analysis,simp)
   187         apply(fast intro: AnnConseq)
   188        apply clarify
   189        apply(frule ann_hoare_case_analysis,simp)
   190        apply clarify
   191        apply(rule conjI)
   192         apply force
   193        apply(rule AnnSeq,simp)
   194        apply(fast intro: AnnConseq)
   195 --{* Cond1 *}
   196       apply clarify
   197       apply(frule ann_hoare_case_analysis,simp)
   198       apply(fast intro: AnnConseq)
   199      apply clarify
   200      apply(frule ann_hoare_case_analysis,simp)
   201      apply(fast intro: AnnConseq)
   202 --{* Cond2 *}
   203     apply clarify
   204     apply(frule ann_hoare_case_analysis,simp)
   205     apply(fast intro: AnnConseq)
   206    apply clarify
   207    apply(frule ann_hoare_case_analysis,simp)
   208    apply(fast intro: AnnConseq)
   209 --{* While *}
   210   apply clarify
   211   apply(frule ann_hoare_case_analysis,simp)
   212   apply force
   213  apply clarify
   214  apply(frule ann_hoare_case_analysis,simp)
   215  apply auto
   216  apply(rule AnnSeq)
   217   apply simp
   218  apply(rule AnnWhile)
   219   apply simp_all
   220 --{* Await *}
   221 apply(frule ann_hoare_case_analysis,simp)
   222 apply clarify
   223 apply(drule atom_hoare_sound)
   224  apply simp 
   225 apply(simp add: com_validity_def SEM_def sem_def)
   226 apply(simp add: Help All_None_def)
   227 apply force
   228 done
   229 
   230 lemma Strong_Soundness_aux: "\<lbrakk> (Some c, s) -*\<rightarrow> (co, t); s \<in> pre c; \<turnstile> c q \<rbrakk>  
   231   \<Longrightarrow> if co = None then t \<in> q else t \<in> pre (the co) \<and> \<turnstile> (the co) q"
   232 apply(erule rtrancl_induct2)
   233  apply simp
   234 apply(case_tac "a")
   235  apply(fast elim: ann_transition_cases)
   236 apply(erule Strong_Soundness_aux_aux)
   237  apply simp
   238 apply simp_all
   239 done
   240 
   241 lemma Strong_Soundness: "\<lbrakk> (Some c, s)-*\<rightarrow>(co, t); s \<in> pre c; \<turnstile> c q \<rbrakk>  
   242   \<Longrightarrow> if co = None then t\<in>q else t \<in> pre (the co)"
   243 apply(force dest:Strong_Soundness_aux)
   244 done
   245 
   246 lemma ann_hoare_sound: "\<turnstile> c q  \<Longrightarrow> \<Turnstile> c q"
   247 apply (unfold ann_com_validity_def ann_SEM_def ann_sem_def)
   248 apply clarify
   249 apply(drule Strong_Soundness)
   250 apply simp_all
   251 done
   252 
   253 subsection {* Soundness of the System for Parallel Programs *}
   254 
   255 lemma Parallel_length_post_P1: "(Parallel Ts,s) -P1\<rightarrow> (R', t) \<Longrightarrow>  
   256   (\<exists>Rs. R' = (Parallel Rs) \<and> (length Rs) = (length Ts) \<and>
   257   (\<forall>i. i<length Ts \<longrightarrow> post(Rs ! i) = post(Ts ! i)))"
   258 apply(erule transition_cases)
   259 apply simp
   260 apply clarify
   261 apply(case_tac "i=ia")
   262 apply simp+
   263 done
   264 
   265 lemma Parallel_length_post_PStar: "(Parallel Ts,s) -P*\<rightarrow> (R',t) \<Longrightarrow>   
   266   (\<exists>Rs. R' = (Parallel Rs) \<and> (length Rs) = (length Ts) \<and>  
   267   (\<forall>i. i<length Ts \<longrightarrow> post(Ts ! i) = post(Rs ! i)))"
   268 apply(erule rtrancl_induct2)
   269  apply(simp_all)
   270 apply clarify
   271 apply simp
   272 apply(drule Parallel_length_post_P1)
   273 apply auto
   274 done
   275 
   276 lemma assertions_lemma: "pre c \<in> assertions c"
   277 apply(rule ann_com_com.induct [THEN conjunct1])
   278 apply auto
   279 done
   280 
   281 lemma interfree_aux1 [rule_format]: 
   282   "(c,s) -1\<rightarrow> (r,t)  \<longrightarrow> (interfree_aux(c1, q1, c) \<longrightarrow> interfree_aux(c1, q1, r))"
   283 apply (rule ann_transition_transition.induct [THEN conjunct1])
   284 apply(safe)
   285 prefer 13
   286 apply (rule TrueI)
   287 apply (simp_all add:interfree_aux_def)
   288 apply force+
   289 done
   290 
   291 lemma interfree_aux2 [rule_format]: 
   292   "(c,s) -1\<rightarrow> (r,t) \<longrightarrow> (interfree_aux(c, q, a)  \<longrightarrow> interfree_aux(r, q, a) )"
   293 apply (rule ann_transition_transition.induct [THEN conjunct1])
   294 apply(force simp add:interfree_aux_def)+
   295 done
   296 
   297 lemma interfree_lemma: "\<lbrakk> (Some c, s) -1\<rightarrow> (r, t);interfree Ts ; i<length Ts;  
   298            Ts!i = (Some c, q) \<rbrakk> \<Longrightarrow> interfree (Ts[i:= (r, q)])"
   299 apply(simp add: interfree_def)
   300 apply clarify
   301 apply(case_tac "i=j")
   302  apply(drule_tac t = "ia" in not_sym)
   303  apply simp_all
   304 apply(force elim: interfree_aux1)
   305 apply(force elim: interfree_aux2 simp add:nth_list_update)
   306 done
   307 
   308 text {* Strong Soundness Theorem for Parallel Programs:*}
   309 
   310 lemma Parallel_Strong_Soundness_Seq_aux: 
   311   "\<lbrakk>interfree Ts; i<length Ts; com(Ts ! i) = Some(AnnSeq c0 c1) \<rbrakk> 
   312   \<Longrightarrow>  interfree (Ts[i:=(Some c0, pre c1)])"
   313 apply(simp add: interfree_def)
   314 apply clarify
   315 apply(case_tac "i=j")
   316  apply(force simp add: nth_list_update interfree_aux_def)
   317 apply(case_tac "i=ia")
   318  apply(erule_tac x=ia in allE)
   319  apply(force simp add:interfree_aux_def assertions_lemma)
   320 apply simp
   321 done
   322 
   323 lemma Parallel_Strong_Soundness_Seq [rule_format (no_asm)]: 
   324  "\<lbrakk> \<forall>i<length Ts. (if com(Ts!i) = None then b \<in> post(Ts!i) 
   325   else b \<in> pre(the(com(Ts!i))) \<and> \<turnstile> the(com(Ts!i)) post(Ts!i));  
   326   com(Ts ! i) = Some(AnnSeq c0 c1); i<length Ts; interfree Ts \<rbrakk> \<Longrightarrow> 
   327  (\<forall>ia<length Ts. (if com(Ts[i:=(Some c0, pre c1)]! ia) = None  
   328   then b \<in> post(Ts[i:=(Some c0, pre c1)]! ia) 
   329  else b \<in> pre(the(com(Ts[i:=(Some c0, pre c1)]! ia))) \<and>  
   330  \<turnstile> the(com(Ts[i:=(Some c0, pre c1)]! ia)) post(Ts[i:=(Some c0, pre c1)]! ia))) 
   331   \<and> interfree (Ts[i:= (Some c0, pre c1)])"
   332 apply(rule conjI)
   333  apply safe
   334  apply(case_tac "i=ia")
   335   apply simp
   336   apply(force dest: ann_hoare_case_analysis)
   337  apply simp
   338 apply(fast elim: Parallel_Strong_Soundness_Seq_aux)
   339 done
   340 
   341 lemma Parallel_Strong_Soundness_aux_aux [rule_format]: 
   342  "(Some c, b) -1\<rightarrow> (co, t) \<longrightarrow>  
   343   (\<forall>Ts. i<length Ts \<longrightarrow> com(Ts ! i) = Some c \<longrightarrow>  
   344   (\<forall>i<length Ts. (if com(Ts ! i) = None then b\<in>post(Ts!i)  
   345   else b\<in>pre(the(com(Ts!i))) \<and> \<turnstile> the(com(Ts!i)) post(Ts!i))) \<longrightarrow>  
   346  interfree Ts \<longrightarrow>  
   347   (\<forall>j. j<length Ts \<and> i\<noteq>j \<longrightarrow> (if com(Ts!j) = None then t\<in>post(Ts!j)  
   348   else t\<in>pre(the(com(Ts!j))) \<and> \<turnstile> the(com(Ts!j)) post(Ts!j))) )"
   349 apply(rule ann_transition_transition.induct [THEN conjunct1])
   350 apply safe
   351 prefer 11
   352 apply(rule TrueI)
   353 apply simp_all
   354 --{* Basic *}
   355    apply(erule_tac x = "i" in all_dupE, erule (1) notE impE)
   356    apply(erule_tac x = "j" in allE , erule (1) notE impE)
   357    apply(simp add: interfree_def)
   358    apply(erule_tac x = "j" in allE,simp)
   359    apply(erule_tac x = "i" in allE,simp)
   360    apply(drule_tac t = "i" in not_sym)
   361    apply(case_tac "com(Ts ! j)=None")
   362     apply(force intro: converse_rtrancl_into_rtrancl
   363           simp add: interfree_aux_def com_validity_def SEM_def sem_def All_None_def)
   364    apply(simp add:interfree_aux_def)
   365    apply clarify
   366    apply simp
   367    apply(erule_tac x="pre y" in ballE)
   368     apply(force intro: converse_rtrancl_into_rtrancl 
   369           simp add: com_validity_def SEM_def sem_def All_None_def)
   370    apply(simp add:assertions_lemma)
   371 --{* Seqs *}
   372   apply(erule_tac x = "Ts[i:=(Some c0, pre c1)]" in allE)
   373   apply(drule  Parallel_Strong_Soundness_Seq,simp+)
   374  apply(erule_tac x = "Ts[i:=(Some c0, pre c1)]" in allE)
   375  apply(drule  Parallel_Strong_Soundness_Seq,simp+)
   376 --{* Await *}
   377 apply(rule_tac x = "i" in allE , assumption , erule (1) notE impE)
   378 apply(erule_tac x = "j" in allE , erule (1) notE impE)
   379 apply(simp add: interfree_def)
   380 apply(erule_tac x = "j" in allE,simp)
   381 apply(erule_tac x = "i" in allE,simp)
   382 apply(drule_tac t = "i" in not_sym)
   383 apply(case_tac "com(Ts ! j)=None")
   384  apply(force intro: converse_rtrancl_into_rtrancl simp add: interfree_aux_def 
   385         com_validity_def SEM_def sem_def All_None_def Help)
   386 apply(simp add:interfree_aux_def)
   387 apply clarify
   388 apply simp
   389 apply(erule_tac x="pre y" in ballE)
   390  apply(force intro: converse_rtrancl_into_rtrancl 
   391        simp add: com_validity_def SEM_def sem_def All_None_def Help)
   392 apply(simp add:assertions_lemma)
   393 done
   394 
   395 lemma Parallel_Strong_Soundness_aux [rule_format]: 
   396  "\<lbrakk>(Ts',s) -P*\<rightarrow> (Rs',t);  Ts' = (Parallel Ts); interfree Ts;
   397  \<forall>i. i<length Ts \<longrightarrow> (\<exists>c q. (Ts ! i) = (Some c, q) \<and> s\<in>(pre c) \<and> \<turnstile> c q ) \<rbrakk> \<Longrightarrow>  
   398   \<forall>Rs. Rs' = (Parallel Rs) \<longrightarrow> (\<forall>j. j<length Rs \<longrightarrow> 
   399   (if com(Rs ! j) = None then t\<in>post(Ts ! j) 
   400   else t\<in>pre(the(com(Rs ! j))) \<and> \<turnstile> the(com(Rs ! j)) post(Ts ! j))) \<and> interfree Rs"
   401 apply(erule rtrancl_induct2)
   402  apply clarify
   403 --{* Base *}
   404  apply force
   405 --{* Induction step *}
   406 apply clarify
   407 apply(drule Parallel_length_post_PStar)
   408 apply clarify
   409 apply (ind_cases "(Parallel Ts, s) -P1\<rightarrow> (Parallel Rs, t)" for Ts s Rs t)
   410 apply(rule conjI)
   411  apply clarify
   412  apply(case_tac "i=j")
   413   apply(simp split del:split_if)
   414   apply(erule Strong_Soundness_aux_aux,simp+)
   415    apply force
   416   apply force
   417  apply(simp split del: split_if)
   418  apply(erule Parallel_Strong_Soundness_aux_aux)
   419  apply(simp_all add: split del:split_if)
   420  apply force
   421 apply(rule interfree_lemma)
   422 apply simp_all
   423 done
   424 
   425 lemma Parallel_Strong_Soundness: 
   426  "\<lbrakk>(Parallel Ts, s) -P*\<rightarrow> (Parallel Rs, t); interfree Ts; j<length Rs; 
   427   \<forall>i. i<length Ts \<longrightarrow> (\<exists>c q. Ts ! i = (Some c, q) \<and> s\<in>pre c \<and> \<turnstile> c q) \<rbrakk> \<Longrightarrow>  
   428   if com(Rs ! j) = None then t\<in>post(Ts ! j) else t\<in>pre (the(com(Rs ! j)))"
   429 apply(drule  Parallel_Strong_Soundness_aux)
   430 apply simp+
   431 done
   432 
   433 lemma oghoare_sound [rule_format]: "\<parallel>- p c q \<longrightarrow> \<parallel>= p c q"
   434 apply (unfold com_validity_def)
   435 apply(rule oghoare_induct)
   436 apply(rule TrueI)+
   437 --{* Parallel *}     
   438       apply(simp add: SEM_def sem_def)
   439       apply(clarify, rename_tac x y i Ts')
   440       apply(frule Parallel_length_post_PStar)
   441       apply clarify
   442       apply(drule_tac j=i in Parallel_Strong_Soundness)
   443          apply clarify
   444         apply simp
   445        apply force
   446       apply simp
   447       apply(erule_tac V = "\<forall>i. ?P i" in thin_rl)
   448       apply(drule_tac s = "length Rs" in sym)
   449       apply(erule allE, erule impE, assumption)
   450       apply(force dest: nth_mem simp add: All_None_def)
   451 --{* Basic *}
   452     apply(simp add: SEM_def sem_def)
   453     apply(force dest: rtrancl_imp_UN_rel_pow Basic_ntran)
   454 --{* Seq *}
   455    apply(rule subset_trans)
   456     prefer 2 apply assumption
   457    apply(simp add: L3_5ii L3_5i)
   458 --{* Cond *}
   459   apply(simp add: L3_5iv)
   460 --{* While *}
   461  apply(simp add: L3_5v)
   462  apply (blast dest: SEM_fwhile) 
   463 --{* Conseq *}
   464 apply(auto simp add: SEM_def sem_def)
   465 done
   466 
   467 end