src/HOL/Hoare_Parallel/RG_Hoare.thy
author wenzelm
Wed Apr 10 21:20:35 2013 +0200 (2013-04-10)
changeset 51692 ecd34f863242
parent 42174 d0be2722ce9f
child 52597 a8a81453833d
permissions -rw-r--r--
tuned pretty layout: avoid nested Pretty.string_of, which merely happens to work with Isabelle/jEdit since formatting is delegated to Scala side;
declare command "print_case_translations" where it is actually defined;
prensani@13020
     1
header {* \section{The Proof System} *}
prensani@13020
     2
haftmann@16417
     3
theory RG_Hoare imports RG_Tran begin
prensani@13020
     4
prensani@13020
     5
subsection {* Proof System for Component Programs *}
prensani@13020
     6
haftmann@32687
     7
declare Un_subset_iff [simp del] le_sup_iff [simp del]
haftmann@32687
     8
declare Cons_eq_map_conv [iff]
paulson@15102
     9
haftmann@35416
    10
definition stable :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool" where  
prensani@13020
    11
  "stable \<equiv> \<lambda>f g. (\<forall>x y. x \<in> f \<longrightarrow> (x, y) \<in> g \<longrightarrow> y \<in> f)" 
prensani@13020
    12
berghofe@23746
    13
inductive
berghofe@23746
    14
  rghoare :: "['a com, 'a set, ('a \<times> 'a) set, ('a \<times> 'a) set, 'a set] \<Rightarrow> bool"  
berghofe@23746
    15
    ("\<turnstile> _ sat [_, _, _, _]" [60,0,0,0,0] 45)
berghofe@23746
    16
where
prensani@13099
    17
  Basic: "\<lbrakk> pre \<subseteq> {s. f s \<in> post}; {(s,t). s \<in> pre \<and> (t=f s \<or> t=s)} \<subseteq> guar; 
prensani@13020
    18
            stable pre rely; stable post rely \<rbrakk> 
prensani@13020
    19
           \<Longrightarrow> \<turnstile> Basic f sat [pre, rely, guar, post]"
prensani@13020
    20
berghofe@23746
    21
| Seq: "\<lbrakk> \<turnstile> P sat [pre, rely, guar, mid]; \<turnstile> Q sat [mid, rely, guar, post] \<rbrakk> 
prensani@13020
    22
           \<Longrightarrow> \<turnstile> Seq P Q sat [pre, rely, guar, post]"
prensani@13020
    23
berghofe@23746
    24
| Cond: "\<lbrakk> stable pre rely; \<turnstile> P1 sat [pre \<inter> b, rely, guar, post];
prensani@13020
    25
           \<turnstile> P2 sat [pre \<inter> -b, rely, guar, post]; \<forall>s. (s,s)\<in>guar \<rbrakk>
prensani@13020
    26
          \<Longrightarrow> \<turnstile> Cond b P1 P2 sat [pre, rely, guar, post]"
prensani@13020
    27
berghofe@23746
    28
| While: "\<lbrakk> stable pre rely; (pre \<inter> -b) \<subseteq> post; stable post rely;
prensani@13020
    29
            \<turnstile> P sat [pre \<inter> b, rely, guar, pre]; \<forall>s. (s,s)\<in>guar \<rbrakk>
prensani@13020
    30
          \<Longrightarrow> \<turnstile> While b P sat [pre, rely, guar, post]"
prensani@13020
    31
berghofe@23746
    32
| Await: "\<lbrakk> stable pre rely; stable post rely; 
prensani@13022
    33
            \<forall>V. \<turnstile> P sat [pre \<inter> b \<inter> {V}, {(s, t). s = t}, 
prensani@13022
    34
                UNIV, {s. (V, s) \<in> guar} \<inter> post] \<rbrakk>
prensani@13020
    35
           \<Longrightarrow> \<turnstile> Await b P sat [pre, rely, guar, post]"
prensani@13020
    36
  
berghofe@23746
    37
| Conseq: "\<lbrakk> pre \<subseteq> pre'; rely \<subseteq> rely'; guar' \<subseteq> guar; post' \<subseteq> post;
prensani@13020
    38
             \<turnstile> P sat [pre', rely', guar', post'] \<rbrakk>
prensani@13020
    39
            \<Longrightarrow> \<turnstile> P sat [pre, rely, guar, post]"
prensani@13020
    40
haftmann@35416
    41
definition Pre :: "'a rgformula \<Rightarrow> 'a set" where
prensani@13020
    42
  "Pre x \<equiv> fst(snd x)"
haftmann@35416
    43
haftmann@35416
    44
definition Post :: "'a rgformula \<Rightarrow> 'a set" where
prensani@13020
    45
  "Post x \<equiv> snd(snd(snd(snd x)))"
haftmann@35416
    46
haftmann@35416
    47
definition Rely :: "'a rgformula \<Rightarrow> ('a \<times> 'a) set" where
prensani@13020
    48
  "Rely x \<equiv> fst(snd(snd x))"
haftmann@35416
    49
haftmann@35416
    50
definition Guar :: "'a rgformula \<Rightarrow> ('a \<times> 'a) set" where
prensani@13020
    51
  "Guar x \<equiv> fst(snd(snd(snd x)))"
haftmann@35416
    52
haftmann@35416
    53
definition Com :: "'a rgformula \<Rightarrow> 'a com" where
prensani@13020
    54
  "Com x \<equiv> fst x"
prensani@13020
    55
prensani@13020
    56
subsection {* Proof System for Parallel Programs *}
prensani@13020
    57
wenzelm@42174
    58
type_synonym 'a par_rgformula =
wenzelm@42174
    59
  "('a rgformula) list \<times> 'a set \<times> ('a \<times> 'a) set \<times> ('a \<times> 'a) set \<times> 'a set"
prensani@13020
    60
berghofe@23746
    61
inductive
berghofe@23746
    62
  par_rghoare :: "('a rgformula) list \<Rightarrow> 'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> 'a set \<Rightarrow> bool"
berghofe@23746
    63
    ("\<turnstile> _ SAT [_, _, _, _]" [60,0,0,0,0] 45)
berghofe@23746
    64
where
prensani@13020
    65
  Parallel: 
prensani@13020
    66
  "\<lbrakk> \<forall>i<length xs. rely \<union> (\<Union>j\<in>{j. j<length xs \<and> j\<noteq>i}. Guar(xs!j)) \<subseteq> Rely(xs!i);
prensani@13020
    67
    (\<Union>j\<in>{j. j<length xs}. Guar(xs!j)) \<subseteq> guar;
prensani@13020
    68
     pre \<subseteq> (\<Inter>i\<in>{i. i<length xs}. Pre(xs!i)); 
prensani@13020
    69
    (\<Inter>i\<in>{i. i<length xs}. Post(xs!i)) \<subseteq> post;
prensani@13020
    70
    \<forall>i<length xs. \<turnstile> Com(xs!i) sat [Pre(xs!i),Rely(xs!i),Guar(xs!i),Post(xs!i)] \<rbrakk>
prensani@13020
    71
   \<Longrightarrow>  \<turnstile> xs SAT [pre, rely, guar, post]"
prensani@13020
    72
prensani@13020
    73
section {* Soundness*}
prensani@13020
    74
prensani@13020
    75
subsubsection {* Some previous lemmas *}
prensani@13020
    76
prensani@13020
    77
lemma tl_of_assum_in_assum: 
prensani@13020
    78
  "(P, s) # (P, t) # xs \<in> assum (pre, rely) \<Longrightarrow> stable pre rely 
prensani@13020
    79
  \<Longrightarrow> (P, t) # xs \<in> assum (pre, rely)"
prensani@13020
    80
apply(simp add:assum_def)
prensani@13020
    81
apply clarify
prensani@13020
    82
apply(rule conjI)
prensani@13020
    83
 apply(erule_tac x=0 in allE)
prensani@13020
    84
 apply(simp (no_asm_use)only:stable_def)
prensani@13020
    85
 apply(erule allE,erule allE,erule impE,assumption,erule mp)
prensani@13020
    86
 apply(simp add:Env)
prensani@13020
    87
apply clarify
prensani@13020
    88
apply(erule_tac x="Suc i" in allE)
prensani@13020
    89
apply simp
prensani@13020
    90
done
prensani@13020
    91
prensani@13020
    92
lemma etran_in_comm: 
prensani@13020
    93
  "(P, t) # xs \<in> comm(guar, post) \<Longrightarrow> (P, s) # (P, t) # xs \<in> comm(guar, post)"
prensani@13020
    94
apply(simp add:comm_def)
prensani@13020
    95
apply clarify
prensani@13020
    96
apply(case_tac i,simp+)
prensani@13020
    97
done
prensani@13020
    98
prensani@13020
    99
lemma ctran_in_comm: 
prensani@13020
   100
  "\<lbrakk>(s, s) \<in> guar; (Q, s) # xs \<in> comm(guar, post)\<rbrakk> 
prensani@13020
   101
  \<Longrightarrow> (P, s) # (Q, s) # xs \<in> comm(guar, post)"
prensani@13020
   102
apply(simp add:comm_def)
prensani@13020
   103
apply clarify
prensani@13020
   104
apply(case_tac i,simp+)
prensani@13020
   105
done
prensani@13020
   106
prensani@13020
   107
lemma takecptn_is_cptn [rule_format, elim!]: 
prensani@13020
   108
  "\<forall>j. c \<in> cptn \<longrightarrow> take (Suc j) c \<in> cptn"
prensani@13020
   109
apply(induct "c")
berghofe@23746
   110
 apply(force elim: cptn.cases)
prensani@13020
   111
apply clarify
prensani@13020
   112
apply(case_tac j) 
prensani@13020
   113
 apply simp
prensani@13020
   114
 apply(rule CptnOne)
prensani@13020
   115
apply simp
berghofe@23746
   116
apply(force intro:cptn.intros elim:cptn.cases)
prensani@13020
   117
done
prensani@13020
   118
prensani@13020
   119
lemma dropcptn_is_cptn [rule_format,elim!]: 
prensani@13020
   120
  "\<forall>j<length c. c \<in> cptn \<longrightarrow> drop j c \<in> cptn"
prensani@13020
   121
apply(induct "c")
berghofe@23746
   122
 apply(force elim: cptn.cases)
prensani@13020
   123
apply clarify
prensani@13020
   124
apply(case_tac j,simp+) 
berghofe@23746
   125
apply(erule cptn.cases)
prensani@13020
   126
  apply simp
prensani@13020
   127
 apply force
prensani@13020
   128
apply force
prensani@13020
   129
done
prensani@13020
   130
prensani@13020
   131
lemma takepar_cptn_is_par_cptn [rule_format,elim]: 
prensani@13020
   132
  "\<forall>j. c \<in> par_cptn \<longrightarrow> take (Suc j) c \<in> par_cptn"
prensani@13020
   133
apply(induct "c")
berghofe@23746
   134
 apply(force elim: cptn.cases)
prensani@13020
   135
apply clarify
prensani@13020
   136
apply(case_tac j,simp) 
prensani@13020
   137
 apply(rule ParCptnOne)
berghofe@23746
   138
apply(force intro:par_cptn.intros elim:par_cptn.cases)
prensani@13020
   139
done
prensani@13020
   140
prensani@13020
   141
lemma droppar_cptn_is_par_cptn [rule_format]:
prensani@13020
   142
  "\<forall>j<length c. c \<in> par_cptn \<longrightarrow> drop j c \<in> par_cptn"
prensani@13020
   143
apply(induct "c")
berghofe@23746
   144
 apply(force elim: par_cptn.cases)
prensani@13020
   145
apply clarify
prensani@13020
   146
apply(case_tac j,simp+) 
berghofe@23746
   147
apply(erule par_cptn.cases)
prensani@13020
   148
  apply simp
prensani@13020
   149
 apply force
prensani@13020
   150
apply force
prensani@13020
   151
done
prensani@13020
   152
prensani@13020
   153
lemma tl_of_cptn_is_cptn: "\<lbrakk>x # xs \<in> cptn; xs \<noteq> []\<rbrakk> \<Longrightarrow> xs  \<in> cptn"
prensani@13020
   154
apply(subgoal_tac "1 < length (x # xs)") 
prensani@13020
   155
 apply(drule dropcptn_is_cptn,simp+)
prensani@13020
   156
done
prensani@13020
   157
prensani@13020
   158
lemma not_ctran_None [rule_format]: 
prensani@13020
   159
  "\<forall>s. (None, s)#xs \<in> cptn \<longrightarrow> (\<forall>i<length xs. ((None, s)#xs)!i -e\<rightarrow> xs!i)"
prensani@13020
   160
apply(induct xs,simp+)
prensani@13020
   161
apply clarify
berghofe@23746
   162
apply(erule cptn.cases,simp)
prensani@13020
   163
 apply simp
prensani@13020
   164
 apply(case_tac i,simp)
prensani@13020
   165
  apply(rule Env)
prensani@13020
   166
 apply simp
berghofe@23746
   167
apply(force elim:ctran.cases)
prensani@13020
   168
done
prensani@13020
   169
prensani@13020
   170
lemma cptn_not_empty [simp]:"[] \<notin> cptn"
berghofe@23746
   171
apply(force elim:cptn.cases)
prensani@13020
   172
done
prensani@13020
   173
prensani@13020
   174
lemma etran_or_ctran [rule_format]: 
prensani@13020
   175
  "\<forall>m i. x\<in>cptn \<longrightarrow> m \<le> length x 
prensani@13022
   176
   \<longrightarrow> (\<forall>i. Suc i < m \<longrightarrow> \<not> x!i -c\<rightarrow> x!Suc i) \<longrightarrow> Suc i < m 
prensani@13022
   177
   \<longrightarrow> x!i -e\<rightarrow> x!Suc i"
prensani@13020
   178
apply(induct x,simp)
prensani@13020
   179
apply clarify
berghofe@23746
   180
apply(erule cptn.cases,simp)
prensani@13020
   181
 apply(case_tac i,simp)
prensani@13020
   182
  apply(rule Env)
prensani@13020
   183
 apply simp
prensani@13020
   184
 apply(erule_tac x="m - 1" in allE)
prensani@13020
   185
 apply(case_tac m,simp,simp)
prensani@13020
   186
 apply(subgoal_tac "(\<forall>i. Suc i < nata \<longrightarrow> (((P, t) # xs) ! i, xs ! i) \<notin> ctran)")
prensani@13020
   187
  apply force
prensani@13020
   188
 apply clarify
prensani@13020
   189
 apply(erule_tac x="Suc ia" in allE,simp)
prensani@13020
   190
apply(erule_tac x="0" and P="\<lambda>j. ?H j \<longrightarrow> (?J j) \<notin> ctran" in allE,simp)
prensani@13020
   191
done
prensani@13020
   192
prensani@13020
   193
lemma etran_or_ctran2 [rule_format]: 
prensani@13020
   194
  "\<forall>i. Suc i<length x \<longrightarrow> x\<in>cptn \<longrightarrow> (x!i -c\<rightarrow> x!Suc i \<longrightarrow> \<not> x!i -e\<rightarrow> x!Suc i)
prensani@13020
   195
  \<or> (x!i -e\<rightarrow> x!Suc i \<longrightarrow> \<not> x!i -c\<rightarrow> x!Suc i)"
prensani@13020
   196
apply(induct x)
prensani@13020
   197
 apply simp
prensani@13020
   198
apply clarify
berghofe@23746
   199
apply(erule cptn.cases,simp)
prensani@13020
   200
 apply(case_tac i,simp+)
prensani@13020
   201
apply(case_tac i,simp)
berghofe@23746
   202
 apply(force elim:etran.cases)
prensani@13020
   203
apply simp
prensani@13020
   204
done
prensani@13020
   205
prensani@13020
   206
lemma etran_or_ctran2_disjI1: 
prensani@13020
   207
  "\<lbrakk> x\<in>cptn; Suc i<length x; x!i -c\<rightarrow> x!Suc i\<rbrakk> \<Longrightarrow> \<not> x!i -e\<rightarrow> x!Suc i"
prensani@13020
   208
by(drule etran_or_ctran2,simp_all)
prensani@13020
   209
prensani@13020
   210
lemma etran_or_ctran2_disjI2: 
prensani@13020
   211
  "\<lbrakk> x\<in>cptn; Suc i<length x; x!i -e\<rightarrow> x!Suc i\<rbrakk> \<Longrightarrow> \<not> x!i -c\<rightarrow> x!Suc i"
prensani@13020
   212
by(drule etran_or_ctran2,simp_all)
prensani@13020
   213
prensani@13020
   214
lemma not_ctran_None2 [rule_format]: 
prensani@13020
   215
  "\<lbrakk> (None, s) # xs \<in>cptn; i<length xs\<rbrakk> \<Longrightarrow> \<not> ((None, s) # xs) ! i -c\<rightarrow> xs ! i"
prensani@13020
   216
apply(frule not_ctran_None,simp)
prensani@13020
   217
apply(case_tac i,simp)
berghofe@23746
   218
 apply(force elim:etranE)
prensani@13020
   219
apply simp
prensani@13020
   220
apply(rule etran_or_ctran2_disjI2,simp_all)
prensani@13020
   221
apply(force intro:tl_of_cptn_is_cptn)
prensani@13020
   222
done
prensani@13020
   223
prensani@13020
   224
lemma Ex_first_occurrence [rule_format]: "P (n::nat) \<longrightarrow> (\<exists>m. P m \<and> (\<forall>i<m. \<not> P i))";
prensani@13020
   225
apply(rule nat_less_induct)
prensani@13020
   226
apply clarify
prensani@13020
   227
apply(case_tac "\<forall>m. m<n \<longrightarrow> \<not> P m")
prensani@13020
   228
apply auto
prensani@13020
   229
done
prensani@13020
   230
 
prensani@13020
   231
lemma stability [rule_format]: 
prensani@13020
   232
  "\<forall>j k. x \<in> cptn \<longrightarrow> stable p rely \<longrightarrow> j\<le>k \<longrightarrow> k<length x \<longrightarrow> snd(x!j)\<in>p  \<longrightarrow>
prensani@13022
   233
  (\<forall>i. (Suc i)<length x \<longrightarrow> 
prensani@13022
   234
          (x!i -e\<rightarrow> x!(Suc i)) \<longrightarrow> (snd(x!i), snd(x!(Suc i))) \<in> rely) \<longrightarrow> 
prensani@13020
   235
  (\<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)"
prensani@13020
   236
apply(induct x)
prensani@13020
   237
 apply clarify
berghofe@23746
   238
 apply(force elim:cptn.cases)
prensani@13020
   239
apply clarify
berghofe@23746
   240
apply(erule cptn.cases,simp)
prensani@13020
   241
 apply simp
prensani@13020
   242
 apply(case_tac k,simp,simp)
prensani@13020
   243
 apply(case_tac j,simp) 
prensani@13020
   244
  apply(erule_tac x=0 in allE)
prensani@13020
   245
  apply(erule_tac x="nat" and P="\<lambda>j. (0\<le>j) \<longrightarrow> (?J j)" in allE,simp)
prensani@13020
   246
  apply(subgoal_tac "t\<in>p")
prensani@13020
   247
   apply(subgoal_tac "(\<forall>i. i < length xs \<longrightarrow> ((P, t) # xs) ! i -e\<rightarrow> xs ! i \<longrightarrow> (snd (((P, t) # xs) ! i), snd (xs ! i)) \<in> rely)")
prensani@13020
   248
    apply clarify
prensani@13020
   249
    apply(erule_tac x="Suc i" and P="\<lambda>j. (?H j) \<longrightarrow> (?J j)\<in>etran" in allE,simp)
prensani@13020
   250
   apply clarify
prensani@13020
   251
   apply(erule_tac x="Suc i" and P="\<lambda>j. (?H j) \<longrightarrow> (?J j) \<longrightarrow> (?T j)\<in>rely" in allE,simp)
prensani@13020
   252
  apply(erule_tac x=0 and P="\<lambda>j. (?H j) \<longrightarrow> (?J j)\<in>etran \<longrightarrow> ?T j" in allE,simp)
prensani@13020
   253
  apply(simp(no_asm_use) only:stable_def)
prensani@13020
   254
  apply(erule_tac x=s in allE)
prensani@13020
   255
  apply(erule_tac x=t in allE)
prensani@13020
   256
  apply simp 
prensani@13020
   257
  apply(erule mp)
prensani@13020
   258
  apply(erule mp)
prensani@13020
   259
  apply(rule Env)
prensani@13020
   260
 apply simp
prensani@13020
   261
 apply(erule_tac x="nata" in allE)
prensani@13020
   262
 apply(erule_tac x="nat" and P="\<lambda>j. (?s\<le>j) \<longrightarrow> (?J j)" in allE,simp)
prensani@13020
   263
 apply(subgoal_tac "(\<forall>i. i < length xs \<longrightarrow> ((P, t) # xs) ! i -e\<rightarrow> xs ! i \<longrightarrow> (snd (((P, t) # xs) ! i), snd (xs ! i)) \<in> rely)")
prensani@13020
   264
  apply clarify
prensani@13020
   265
  apply(erule_tac x="Suc i" and P="\<lambda>j. (?H j) \<longrightarrow> (?J j)\<in>etran" in allE,simp)
prensani@13020
   266
 apply clarify
prensani@13020
   267
 apply(erule_tac x="Suc i" and P="\<lambda>j. (?H j) \<longrightarrow> (?J j) \<longrightarrow> (?T j)\<in>rely" in allE,simp)
prensani@13020
   268
apply(case_tac k,simp,simp)
prensani@13020
   269
apply(case_tac j)
prensani@13020
   270
 apply(erule_tac x=0 and P="\<lambda>j. (?H j) \<longrightarrow> (?J j)\<in>etran" in allE,simp)
berghofe@23746
   271
 apply(erule etran.cases,simp)
prensani@13020
   272
apply(erule_tac x="nata" in allE)
prensani@13020
   273
apply(erule_tac x="nat" and P="\<lambda>j. (?s\<le>j) \<longrightarrow> (?J j)" in allE,simp)
prensani@13020
   274
apply(subgoal_tac "(\<forall>i. i < length xs \<longrightarrow> ((Q, t) # xs) ! i -e\<rightarrow> xs ! i \<longrightarrow> (snd (((Q, t) # xs) ! i), snd (xs ! i)) \<in> rely)")
prensani@13020
   275
 apply clarify
prensani@13020
   276
 apply(erule_tac x="Suc i" and P="\<lambda>j. (?H j) \<longrightarrow> (?J j)\<in>etran" in allE,simp)
prensani@13020
   277
apply clarify
prensani@13020
   278
apply(erule_tac x="Suc i" and P="\<lambda>j. (?H j) \<longrightarrow> (?J j) \<longrightarrow> (?T j)\<in>rely" in allE,simp)
prensani@13020
   279
done
prensani@13020
   280
prensani@13020
   281
subsection {* Soundness of the System for Component Programs *}
prensani@13020
   282
prensani@13020
   283
subsubsection {* Soundness of the Basic rule *}
prensani@13020
   284
prensani@13020
   285
lemma unique_ctran_Basic [rule_format]: 
prensani@13020
   286
  "\<forall>s i. x \<in> cptn \<longrightarrow> x ! 0 = (Some (Basic f), s) \<longrightarrow> 
prensani@13022
   287
  Suc i<length x \<longrightarrow> x!i -c\<rightarrow> x!Suc i \<longrightarrow> 
prensani@13022
   288
  (\<forall>j. Suc j<length x \<longrightarrow> i\<noteq>j \<longrightarrow> x!j -e\<rightarrow> x!Suc j)"
prensani@13020
   289
apply(induct x,simp)
prensani@13020
   290
apply simp
prensani@13020
   291
apply clarify
berghofe@23746
   292
apply(erule cptn.cases,simp)
prensani@13020
   293
 apply(case_tac i,simp+)
prensani@13020
   294
 apply clarify
prensani@13020
   295
 apply(case_tac j,simp)
prensani@13020
   296
  apply(rule Env)
prensani@13020
   297
 apply simp
prensani@13020
   298
apply clarify
prensani@13020
   299
apply simp
prensani@13020
   300
apply(case_tac i)
prensani@13020
   301
 apply(case_tac j,simp,simp)
berghofe@23746
   302
 apply(erule ctran.cases,simp_all)
prensani@13020
   303
 apply(force elim: not_ctran_None)
berghofe@23746
   304
apply(ind_cases "((Some (Basic f), sa), Q, t) \<in> ctran" for sa Q t)
prensani@13020
   305
apply simp
prensani@13020
   306
apply(drule_tac i=nat in not_ctran_None,simp)
berghofe@23746
   307
apply(erule etranE,simp)
prensani@13020
   308
done
prensani@13020
   309
prensani@13020
   310
lemma exists_ctran_Basic_None [rule_format]: 
prensani@13020
   311
  "\<forall>s i. x \<in> cptn \<longrightarrow> x ! 0 = (Some (Basic f), s) 
prensani@13020
   312
  \<longrightarrow> i<length x \<longrightarrow> fst(x!i)=None \<longrightarrow> (\<exists>j<i. x!j -c\<rightarrow> x!Suc j)"
prensani@13020
   313
apply(induct x,simp)
prensani@13020
   314
apply simp
prensani@13020
   315
apply clarify
berghofe@23746
   316
apply(erule cptn.cases,simp)
prensani@13020
   317
 apply(case_tac i,simp,simp)
prensani@13020
   318
 apply(erule_tac x=nat in allE,simp)
prensani@13020
   319
 apply clarify
prensani@13020
   320
 apply(rule_tac x="Suc j" in exI,simp,simp)
prensani@13020
   321
apply clarify
prensani@13020
   322
apply(case_tac i,simp,simp)
prensani@13020
   323
apply(rule_tac x=0 in exI,simp)
prensani@13020
   324
done
prensani@13020
   325
webertj@20432
   326
lemma Basic_sound: 
prensani@13020
   327
  " \<lbrakk>pre \<subseteq> {s. f s \<in> post}; {(s, t). s \<in> pre \<and> t = f s} \<subseteq> guar; 
prensani@13020
   328
  stable pre rely; stable post rely\<rbrakk>
prensani@13020
   329
  \<Longrightarrow> \<Turnstile> Basic f sat [pre, rely, guar, post]"
prensani@13020
   330
apply(unfold com_validity_def)
prensani@13020
   331
apply clarify
prensani@13020
   332
apply(simp add:comm_def)
prensani@13020
   333
apply(rule conjI)
prensani@13020
   334
 apply clarify
prensani@13020
   335
 apply(simp add:cp_def assum_def)
prensani@13020
   336
 apply clarify
prensani@13020
   337
 apply(frule_tac j=0 and k=i and p=pre in stability)
prensani@13020
   338
       apply simp_all
prensani@13020
   339
   apply(erule_tac x=ia in allE,simp)
prensani@13020
   340
  apply(erule_tac i=i and f=f in unique_ctran_Basic,simp_all)
prensani@13020
   341
 apply(erule subsetD,simp)
prensani@13020
   342
 apply(case_tac "x!i")
prensani@13020
   343
 apply clarify
prensani@13020
   344
 apply(drule_tac s="Some (Basic f)" in sym,simp)
prensani@13020
   345
 apply(thin_tac "\<forall>j. ?H j")
berghofe@23746
   346
 apply(force elim:ctran.cases)
prensani@13020
   347
apply clarify
prensani@13020
   348
apply(simp add:cp_def)
prensani@13020
   349
apply clarify
prensani@13020
   350
apply(frule_tac i="length x - 1" and f=f in exists_ctran_Basic_None,simp+)
prensani@13020
   351
  apply(case_tac x,simp+)
prensani@13020
   352
  apply(rule last_fst_esp,simp add:last_length)
prensani@13020
   353
 apply (case_tac x,simp+)
prensani@13020
   354
apply(simp add:assum_def)
prensani@13020
   355
apply clarify
prensani@13020
   356
apply(frule_tac j=0 and k="j" and p=pre in stability)
prensani@13020
   357
      apply simp_all
prensani@13020
   358
  apply(erule_tac x=i in allE,simp)
prensani@13020
   359
 apply(erule_tac i=j and f=f in unique_ctran_Basic,simp_all)
prensani@13020
   360
apply(case_tac "x!j")
prensani@13020
   361
apply clarify
prensani@13020
   362
apply simp
prensani@13020
   363
apply(drule_tac s="Some (Basic f)" in sym,simp)
prensani@13020
   364
apply(case_tac "x!Suc j",simp)
berghofe@23746
   365
apply(rule ctran.cases,simp)
webertj@20432
   366
apply(simp_all)
prensani@13020
   367
apply(drule_tac c=sa in subsetD,simp)
prensani@13020
   368
apply clarify
prensani@13020
   369
apply(frule_tac j="Suc j" and k="length x - 1" and p=post in stability,simp_all)
webertj@20432
   370
 apply(case_tac x,simp+)
prensani@13020
   371
 apply(erule_tac x=i in allE)
webertj@20432
   372
apply(erule_tac i=j and f=f in unique_ctran_Basic,simp_all)
webertj@20432
   373
  apply arith+
prensani@13020
   374
apply(case_tac x)
webertj@20432
   375
apply(simp add:last_length)+
prensani@13020
   376
done
prensani@13020
   377
prensani@13020
   378
subsubsection{* Soundness of the Await rule *}
prensani@13020
   379
prensani@13020
   380
lemma unique_ctran_Await [rule_format]: 
prensani@13020
   381
  "\<forall>s i. x \<in> cptn \<longrightarrow> x ! 0 = (Some (Await b c), s) \<longrightarrow> 
prensani@13022
   382
  Suc i<length x \<longrightarrow> x!i -c\<rightarrow> x!Suc i \<longrightarrow> 
prensani@13022
   383
  (\<forall>j. Suc j<length x \<longrightarrow> i\<noteq>j \<longrightarrow> x!j -e\<rightarrow> x!Suc j)"
prensani@13020
   384
apply(induct x,simp+)
prensani@13020
   385
apply clarify
berghofe@23746
   386
apply(erule cptn.cases,simp)
prensani@13020
   387
 apply(case_tac i,simp+)
prensani@13020
   388
 apply clarify
prensani@13020
   389
 apply(case_tac j,simp)
prensani@13020
   390
  apply(rule Env)
prensani@13020
   391
 apply simp
prensani@13020
   392
apply clarify
prensani@13020
   393
apply simp
prensani@13020
   394
apply(case_tac i)
prensani@13020
   395
 apply(case_tac j,simp,simp)
berghofe@23746
   396
 apply(erule ctran.cases,simp_all)
prensani@13020
   397
 apply(force elim: not_ctran_None)
berghofe@23746
   398
apply(ind_cases "((Some (Await b c), sa), Q, t) \<in> ctran" for sa Q t,simp)
prensani@13020
   399
apply(drule_tac i=nat in not_ctran_None,simp)
berghofe@23746
   400
apply(erule etranE,simp)
prensani@13020
   401
done
prensani@13020
   402
prensani@13020
   403
lemma exists_ctran_Await_None [rule_format]: 
prensani@13020
   404
  "\<forall>s i.  x \<in> cptn \<longrightarrow> x ! 0 = (Some (Await b c), s) 
prensani@13020
   405
  \<longrightarrow> i<length x \<longrightarrow> fst(x!i)=None \<longrightarrow> (\<exists>j<i. x!j -c\<rightarrow> x!Suc j)"
prensani@13020
   406
apply(induct x,simp+)
prensani@13020
   407
apply clarify
berghofe@23746
   408
apply(erule cptn.cases,simp)
prensani@13020
   409
 apply(case_tac i,simp+)
prensani@13020
   410
 apply(erule_tac x=nat in allE,simp)
prensani@13020
   411
 apply clarify
prensani@13020
   412
 apply(rule_tac x="Suc j" in exI,simp,simp)
prensani@13020
   413
apply clarify
prensani@13020
   414
apply(case_tac i,simp,simp)
prensani@13020
   415
apply(rule_tac x=0 in exI,simp)
prensani@13020
   416
done
prensani@13020
   417
prensani@13020
   418
lemma Star_imp_cptn: 
prensani@13020
   419
  "(P, s) -c*\<rightarrow> (R, t) \<Longrightarrow> \<exists>l \<in> cp P s. (last l)=(R, t)
prensani@13020
   420
  \<and> (\<forall>i. Suc i<length l \<longrightarrow> l!i -c\<rightarrow> l!Suc i)"
prensani@13020
   421
apply (erule converse_rtrancl_induct2)
prensani@13020
   422
 apply(rule_tac x="[(R,t)]" in bexI)
prensani@13020
   423
  apply simp
prensani@13020
   424
 apply(simp add:cp_def)
prensani@13020
   425
 apply(rule CptnOne)
prensani@13020
   426
apply clarify
prensani@13020
   427
apply(rule_tac x="(a, b)#l" in bexI)
prensani@13020
   428
 apply (rule conjI)
prensani@13020
   429
  apply(case_tac l,simp add:cp_def)
prensani@13020
   430
  apply(simp add:last_length)
prensani@13020
   431
 apply clarify
prensani@13020
   432
apply(case_tac i,simp)
prensani@13020
   433
apply(simp add:cp_def)
prensani@13020
   434
apply force
prensani@13020
   435
apply(simp add:cp_def)
prensani@13020
   436
 apply(case_tac l)
berghofe@23746
   437
 apply(force elim:cptn.cases)
prensani@13020
   438
apply simp
prensani@13020
   439
apply(erule CptnComp)
prensani@13020
   440
apply clarify
prensani@13020
   441
done
prensani@13020
   442
 
prensani@13020
   443
lemma Await_sound: 
prensani@13020
   444
  "\<lbrakk>stable pre rely; stable post rely;
prensani@13022
   445
  \<forall>V. \<turnstile> P sat [pre \<inter> b \<inter> {s. s = V}, {(s, t). s = t}, 
prensani@13022
   446
                 UNIV, {s. (V, s) \<in> guar} \<inter> post] \<and>
prensani@13022
   447
  \<Turnstile> P sat [pre \<inter> b \<inter> {s. s = V}, {(s, t). s = t}, 
prensani@13022
   448
                 UNIV, {s. (V, s) \<in> guar} \<inter> post] \<rbrakk>
prensani@13020
   449
  \<Longrightarrow> \<Turnstile> Await b P sat [pre, rely, guar, post]"
prensani@13020
   450
apply(unfold com_validity_def)
prensani@13020
   451
apply clarify
prensani@13020
   452
apply(simp add:comm_def)
prensani@13020
   453
apply(rule conjI)
prensani@13020
   454
 apply clarify
prensani@13020
   455
 apply(simp add:cp_def assum_def)
prensani@13020
   456
 apply clarify
prensani@13020
   457
 apply(frule_tac j=0 and k=i and p=pre in stability,simp_all)
prensani@13020
   458
   apply(erule_tac x=ia in allE,simp)
prensani@13020
   459
  apply(subgoal_tac "x\<in> cp (Some(Await b P)) s")
prensani@13020
   460
  apply(erule_tac i=i in unique_ctran_Await,force,simp_all)
prensani@13020
   461
  apply(simp add:cp_def)
prensani@13020
   462
--{* here starts the different part. *}
berghofe@23746
   463
 apply(erule ctran.cases,simp_all)
prensani@13020
   464
 apply(drule Star_imp_cptn) 
prensani@13020
   465
 apply clarify
prensani@13020
   466
 apply(erule_tac x=sa in allE)
prensani@13020
   467
 apply clarify
prensani@13020
   468
 apply(erule_tac x=sa in allE)
prensani@13020
   469
 apply(drule_tac c=l in subsetD)
prensani@13020
   470
  apply (simp add:cp_def)
prensani@13020
   471
  apply clarify
prensani@13020
   472
  apply(erule_tac x=ia and P="\<lambda>i. ?H i \<longrightarrow> (?J i,?I i)\<in>ctran" in allE,simp)
berghofe@23746
   473
  apply(erule etranE,simp)
prensani@13020
   474
 apply simp
prensani@13020
   475
apply clarify
prensani@13020
   476
apply(simp add:cp_def)
prensani@13020
   477
apply clarify
prensani@13020
   478
apply(frule_tac i="length x - 1" in exists_ctran_Await_None,force)
prensani@13020
   479
  apply (case_tac x,simp+)
prensani@13020
   480
 apply(rule last_fst_esp,simp add:last_length)
prensani@13020
   481
 apply(case_tac x, (simp add:cptn_not_empty)+)
prensani@13020
   482
apply clarify
prensani@13020
   483
apply(simp add:assum_def)
prensani@13020
   484
apply clarify
prensani@13020
   485
apply(frule_tac j=0 and k="j" and p=pre in stability,simp_all)
prensani@13020
   486
  apply(erule_tac x=i in allE,simp)
prensani@13020
   487
 apply(erule_tac i=j in unique_ctran_Await,force,simp_all)
prensani@13020
   488
apply(case_tac "x!j")
prensani@13020
   489
apply clarify
prensani@13020
   490
apply simp
prensani@13020
   491
apply(drule_tac s="Some (Await b P)" in sym,simp)
prensani@13020
   492
apply(case_tac "x!Suc j",simp)
berghofe@23746
   493
apply(rule ctran.cases,simp)
webertj@20432
   494
apply(simp_all)
prensani@13020
   495
apply(drule Star_imp_cptn) 
prensani@13020
   496
apply clarify
prensani@13020
   497
apply(erule_tac x=sa in allE)
prensani@13020
   498
apply clarify
prensani@13020
   499
apply(erule_tac x=sa in allE)
prensani@13020
   500
apply(drule_tac c=l in subsetD)
prensani@13020
   501
 apply (simp add:cp_def)
prensani@13020
   502
 apply clarify
prensani@13020
   503
 apply(erule_tac x=i and P="\<lambda>i. ?H i \<longrightarrow> (?J i,?I i)\<in>ctran" in allE,simp)
berghofe@23746
   504
 apply(erule etranE,simp)
prensani@13020
   505
apply simp
prensani@13020
   506
apply clarify
prensani@13020
   507
apply(frule_tac j="Suc j" and k="length x - 1" and p=post in stability,simp_all)
webertj@20432
   508
 apply(case_tac x,simp+)
prensani@13020
   509
 apply(erule_tac x=i in allE)
webertj@20432
   510
apply(erule_tac i=j in unique_ctran_Await,force,simp_all)
webertj@20432
   511
 apply arith+
prensani@13020
   512
apply(case_tac x)
webertj@20432
   513
apply(simp add:last_length)+
prensani@13020
   514
done
prensani@13020
   515
prensani@13020
   516
subsubsection{* Soundness of the Conditional rule *}
prensani@13020
   517
prensani@13020
   518
lemma Cond_sound: 
prensani@13020
   519
  "\<lbrakk> stable pre rely; \<Turnstile> P1 sat [pre \<inter> b, rely, guar, post]; 
prensani@13020
   520
  \<Turnstile> P2 sat [pre \<inter> - b, rely, guar, post]; \<forall>s. (s,s)\<in>guar\<rbrakk>
prensani@13020
   521
  \<Longrightarrow> \<Turnstile> (Cond b P1 P2) sat [pre, rely, guar, post]"
prensani@13020
   522
apply(unfold com_validity_def)
prensani@13020
   523
apply clarify
prensani@13020
   524
apply(simp add:cp_def comm_def)
prensani@13020
   525
apply(case_tac "\<exists>i. Suc i<length x \<and> x!i -c\<rightarrow> x!Suc i")
prensani@13020
   526
 prefer 2
prensani@13020
   527
 apply simp
prensani@13020
   528
 apply clarify
prensani@13020
   529
 apply(frule_tac j="0" and k="length x - 1" and p=pre in stability,simp+)
prensani@13020
   530
     apply(case_tac x,simp+)
prensani@13020
   531
    apply(simp add:assum_def)
prensani@13020
   532
   apply(simp add:assum_def)
prensani@13020
   533
  apply(erule_tac m="length x" in etran_or_ctran,simp+)
prensani@13020
   534
 apply(case_tac x, (simp add:last_length)+)
prensani@13020
   535
apply(erule exE)
prensani@13020
   536
apply(drule_tac n=i and P="\<lambda>i. ?H i \<and> (?J i,?I i)\<in> ctran" in Ex_first_occurrence)
prensani@13020
   537
apply clarify
prensani@13020
   538
apply (simp add:assum_def)
prensani@13020
   539
apply(frule_tac j=0 and k="m" and p=pre in stability,simp+)
prensani@13020
   540
 apply(erule_tac m="Suc m" in etran_or_ctran,simp+)
berghofe@23746
   541
apply(erule ctran.cases,simp_all)
prensani@13020
   542
 apply(erule_tac x="sa" in allE)
prensani@13020
   543
 apply(drule_tac c="drop (Suc m) x" in subsetD)
prensani@13020
   544
  apply simp
prensani@13020
   545
  apply clarify
prensani@13020
   546
 apply simp
wenzelm@17528
   547
 apply clarify
wenzelm@17528
   548
 apply(case_tac "i\<le>m")
wenzelm@17528
   549
  apply(drule le_imp_less_or_eq)
wenzelm@17528
   550
  apply(erule disjE)
wenzelm@17528
   551
   apply(erule_tac x=i in allE, erule impE, assumption)
wenzelm@17528
   552
   apply simp+
wenzelm@17528
   553
 apply(erule_tac x="i - (Suc m)" and P="\<lambda>j. ?H j \<longrightarrow> ?J j \<longrightarrow> (?I j)\<in>guar" in allE)
webertj@20432
   554
 apply(subgoal_tac "(Suc m)+(i - Suc m) \<le> length x")
webertj@20432
   555
  apply(subgoal_tac "(Suc m)+Suc (i - Suc m) \<le> length x")
webertj@20432
   556
   apply(rotate_tac -2)
prensani@13020
   557
   apply simp
prensani@13020
   558
  apply arith
prensani@13020
   559
 apply arith
webertj@20432
   560
apply(case_tac "length (drop (Suc m) x)",simp)
webertj@20432
   561
apply(erule_tac x="sa" in allE)
webertj@20432
   562
back
webertj@20432
   563
apply(drule_tac c="drop (Suc m) x" in subsetD,simp)
webertj@20432
   564
 apply clarify
webertj@20432
   565
apply simp
webertj@20432
   566
apply clarify
webertj@20432
   567
apply(case_tac "i\<le>m")
webertj@20432
   568
 apply(drule le_imp_less_or_eq)
webertj@20432
   569
 apply(erule disjE)
webertj@20432
   570
  apply(erule_tac x=i in allE, erule impE, assumption)
webertj@20432
   571
  apply simp
webertj@20432
   572
 apply simp
webertj@20432
   573
apply(erule_tac x="i - (Suc m)" and P="\<lambda>j. ?H j \<longrightarrow> ?J j \<longrightarrow> (?I j)\<in>guar" in allE)
webertj@20432
   574
apply(subgoal_tac "(Suc m)+(i - Suc m) \<le> length x")
webertj@20432
   575
 apply(subgoal_tac "(Suc m)+Suc (i - Suc m) \<le> length x")
webertj@20432
   576
  apply(rotate_tac -2)
webertj@20432
   577
  apply simp
webertj@20432
   578
 apply arith
webertj@20432
   579
apply arith
webertj@20217
   580
done
prensani@13020
   581
prensani@13020
   582
subsubsection{* Soundness of the Sequential rule *}
prensani@13020
   583
prensani@13020
   584
inductive_cases Seq_cases [elim!]: "(Some (Seq P Q), s) -c\<rightarrow> t"
prensani@13020
   585
prensani@13020
   586
lemma last_lift_not_None: "fst ((lift Q) ((x#xs)!(length xs))) \<noteq> None"
prensani@13020
   587
apply(subgoal_tac "length xs<length (x # xs)")
prensani@13020
   588
 apply(drule_tac Q=Q in  lift_nth)
prensani@13020
   589
 apply(erule ssubst)
prensani@13020
   590
 apply (simp add:lift_def)
prensani@13020
   591
 apply(case_tac "(x # xs) ! length xs",simp)
prensani@13020
   592
apply simp
prensani@13020
   593
done
prensani@13020
   594
nipkow@14025
   595
declare map_eq_Cons_conv [simp del] Cons_eq_map_conv [simp del]
prensani@13020
   596
lemma Seq_sound1 [rule_format]: 
prensani@13020
   597
  "x\<in> cptn_mod \<Longrightarrow> \<forall>s P. x !0=(Some (Seq P Q), s) \<longrightarrow> 
prensani@13020
   598
  (\<forall>i<length x. fst(x!i)\<noteq>Some Q) \<longrightarrow> 
prensani@13020
   599
  (\<exists>xs\<in> cp (Some P) s. x=map (lift Q) xs)"
prensani@13020
   600
apply(erule cptn_mod.induct)
prensani@13020
   601
apply(unfold cp_def)
prensani@13020
   602
apply safe
prensani@13020
   603
apply simp_all
prensani@13020
   604
    apply(simp add:lift_def)
prensani@13020
   605
    apply(rule_tac x="[(Some Pa, sa)]" in exI,simp add:CptnOne)
prensani@13020
   606
   apply(subgoal_tac "(\<forall>i < Suc (length xs). fst (((Some (Seq Pa Q), t) # xs) ! i) \<noteq> Some Q)")
prensani@13020
   607
    apply clarify
nipkow@14025
   608
    apply(rule_tac x="(Some Pa, sa) #(Some Pa, t) # zs" in exI,simp)
prensani@13020
   609
    apply(rule conjI,erule CptnEnv)
berghofe@13601
   610
    apply(simp (no_asm_use) add:lift_def)
prensani@13020
   611
   apply clarify
prensani@13020
   612
   apply(erule_tac x="Suc i" in allE, simp)
berghofe@23746
   613
  apply(ind_cases "((Some (Seq Pa Q), sa), None, t) \<in> ctran" for Pa sa t)
prensani@13020
   614
 apply(rule_tac x="(Some P, sa) # xs" in exI, simp add:cptn_iff_cptn_mod lift_def)
prensani@13020
   615
apply(erule_tac x="length xs" in allE, simp)
prensani@13020
   616
apply(simp only:Cons_lift_append)
prensani@13020
   617
apply(subgoal_tac "length xs < length ((Some P, sa) # xs)")
prensani@13020
   618
 apply(simp only :nth_append length_map last_length nth_map)
prensani@13020
   619
 apply(case_tac "last((Some P, sa) # xs)")
prensani@13020
   620
 apply(simp add:lift_def)
prensani@13020
   621
apply simp
prensani@13020
   622
done
nipkow@14025
   623
declare map_eq_Cons_conv [simp del] Cons_eq_map_conv [simp del]
prensani@13020
   624
prensani@13020
   625
lemma Seq_sound2 [rule_format]: 
prensani@13022
   626
  "x \<in> cptn \<Longrightarrow> \<forall>s P i. x!0=(Some (Seq P Q), s) \<longrightarrow> i<length x 
prensani@13022
   627
  \<longrightarrow> fst(x!i)=Some Q \<longrightarrow>
prensani@13020
   628
  (\<forall>j<i. fst(x!j)\<noteq>(Some Q)) \<longrightarrow>
prensani@13022
   629
  (\<exists>xs ys. xs \<in> cp (Some P) s \<and> length xs=Suc i 
prensani@13022
   630
   \<and> ys \<in> cp (Some Q) (snd(xs !i)) \<and> x=(map (lift Q) xs)@tl ys)"
prensani@13020
   631
apply(erule cptn.induct)
prensani@13020
   632
apply(unfold cp_def)
prensani@13020
   633
apply safe
prensani@13020
   634
apply simp_all
prensani@13020
   635
 apply(case_tac i,simp+)
prensani@13020
   636
 apply(erule allE,erule impE,assumption,simp)
prensani@13020
   637
 apply clarify
prensani@13020
   638
 apply(subgoal_tac "(\<forall>j < nat. fst (((Some (Seq Pa Q), t) # xs) ! j) \<noteq> Some Q)",clarify)
prensani@13020
   639
  prefer 2
prensani@13020
   640
  apply force
prensani@13020
   641
 apply(case_tac xsa,simp,simp)
prensani@13020
   642
 apply(rule_tac x="(Some Pa, sa) #(Some Pa, t) # list" in exI,simp)
prensani@13020
   643
 apply(rule conjI,erule CptnEnv)
berghofe@13601
   644
 apply(simp (no_asm_use) add:lift_def)
prensani@13020
   645
 apply(rule_tac x=ys in exI,simp)
berghofe@23746
   646
apply(ind_cases "((Some (Seq Pa Q), sa), t) \<in> ctran" for Pa sa t)
prensani@13020
   647
 apply simp
prensani@13020
   648
 apply(rule_tac x="(Some Pa, sa)#[(None, ta)]" in exI,simp)
prensani@13020
   649
 apply(rule conjI)
prensani@13020
   650
  apply(drule_tac xs="[]" in CptnComp,force simp add:CptnOne,simp)
prensani@13020
   651
 apply(case_tac i, simp+)
prensani@13020
   652
 apply(case_tac nat,simp+)
prensani@13020
   653
 apply(rule_tac x="(Some Q,ta)#xs" in exI,simp add:lift_def)
prensani@13020
   654
 apply(case_tac nat,simp+)
prensani@13020
   655
 apply(force)
prensani@13020
   656
apply(case_tac i, simp+)
prensani@13020
   657
apply(case_tac nat,simp+)
prensani@13020
   658
apply(erule_tac x="Suc nata" in allE,simp)
prensani@13020
   659
apply clarify
prensani@13020
   660
apply(subgoal_tac "(\<forall>j<Suc nata. fst (((Some (Seq P2 Q), ta) # xs) ! j) \<noteq> Some Q)",clarify)
prensani@13020
   661
 prefer 2
prensani@13020
   662
 apply clarify
prensani@13020
   663
 apply force
prensani@13020
   664
apply(rule_tac x="(Some Pa, sa)#(Some P2, ta)#(tl xsa)" in exI,simp)
prensani@13020
   665
apply(rule conjI,erule CptnComp)
prensani@13020
   666
apply(rule nth_tl_if,force,simp+)
prensani@13020
   667
apply(rule_tac x=ys in exI,simp)
prensani@13020
   668
apply(rule conjI)
prensani@13020
   669
apply(rule nth_tl_if,force,simp+)
prensani@13020
   670
 apply(rule tl_zero,simp+)
prensani@13020
   671
 apply force
prensani@13020
   672
apply(rule conjI,simp add:lift_def)
prensani@13020
   673
apply(subgoal_tac "lift Q (Some P2, ta) =(Some (Seq P2 Q), ta)") 
prensani@13020
   674
 apply(simp add:Cons_lift del:map.simps)
prensani@13020
   675
 apply(rule nth_tl_if)
prensani@13020
   676
   apply force
prensani@13020
   677
  apply simp+
prensani@13020
   678
apply(simp add:lift_def)
prensani@13020
   679
done
prensani@13020
   680
(*
prensani@13020
   681
lemma last_lift_not_None3: "fst (last (map (lift Q) (x#xs))) \<noteq> None"
prensani@13020
   682
apply(simp only:last_length [THEN sym])
prensani@13020
   683
apply(subgoal_tac "length xs<length (x # xs)")
prensani@13020
   684
 apply(drule_tac Q=Q in  lift_nth)
prensani@13020
   685
 apply(erule ssubst)
prensani@13020
   686
 apply (simp add:lift_def)
prensani@13020
   687
 apply(case_tac "(x # xs) ! length xs",simp)
prensani@13020
   688
apply simp
prensani@13020
   689
done
prensani@13020
   690
*)
prensani@13020
   691
prensani@13020
   692
lemma last_lift_not_None2: "fst ((lift Q) (last (x#xs))) \<noteq> None"
prensani@13020
   693
apply(simp only:last_length [THEN sym])
prensani@13020
   694
apply(subgoal_tac "length xs<length (x # xs)")
prensani@13020
   695
 apply(drule_tac Q=Q in  lift_nth)
prensani@13020
   696
 apply(erule ssubst)
prensani@13020
   697
 apply (simp add:lift_def)
prensani@13020
   698
 apply(case_tac "(x # xs) ! length xs",simp)
prensani@13020
   699
apply simp
prensani@13020
   700
done
prensani@13020
   701
prensani@13020
   702
lemma Seq_sound: 
prensani@13020
   703
  "\<lbrakk>\<Turnstile> P sat [pre, rely, guar, mid]; \<Turnstile> Q sat [mid, rely, guar, post]\<rbrakk>
prensani@13020
   704
  \<Longrightarrow> \<Turnstile> Seq P Q sat [pre, rely, guar, post]"
prensani@13020
   705
apply(unfold com_validity_def)
prensani@13020
   706
apply clarify
prensani@13020
   707
apply(case_tac "\<exists>i<length x. fst(x!i)=Some Q")
prensani@13020
   708
 prefer 2
prensani@13020
   709
 apply (simp add:cp_def cptn_iff_cptn_mod)
prensani@13020
   710
 apply clarify
prensani@13020
   711
 apply(frule_tac Seq_sound1,force)
prensani@13020
   712
  apply force
prensani@13020
   713
 apply clarify
prensani@13020
   714
 apply(erule_tac x=s in allE,simp)
prensani@13020
   715
 apply(drule_tac c=xs in subsetD,simp add:cp_def cptn_iff_cptn_mod)
prensani@13020
   716
  apply(simp add:assum_def)
prensani@13020
   717
  apply clarify
prensani@13020
   718
  apply(erule_tac P="\<lambda>j. ?H j \<longrightarrow> ?J j \<longrightarrow> ?I j" in allE,erule impE, assumption)
prensani@13020
   719
  apply(simp add:snd_lift)
prensani@13020
   720
  apply(erule mp)
berghofe@23746
   721
  apply(force elim:etranE intro:Env simp add:lift_def)
prensani@13020
   722
 apply(simp add:comm_def)
prensani@13020
   723
 apply(rule conjI)
prensani@13020
   724
  apply clarify
prensani@13020
   725
  apply(erule_tac P="\<lambda>j. ?H j \<longrightarrow> ?J j \<longrightarrow> ?I j" in allE,erule impE, assumption)
prensani@13020
   726
  apply(simp add:snd_lift)
prensani@13020
   727
  apply(erule mp)
prensani@13020
   728
  apply(case_tac "(xs!i)")
prensani@13020
   729
  apply(case_tac "(xs! Suc i)")
prensani@13020
   730
  apply(case_tac "fst(xs!i)")
prensani@13020
   731
   apply(erule_tac x=i in allE, simp add:lift_def)
prensani@13020
   732
  apply(case_tac "fst(xs!Suc i)")
prensani@13020
   733
   apply(force simp add:lift_def)
prensani@13020
   734
  apply(force simp add:lift_def)
prensani@13020
   735
 apply clarify
prensani@13020
   736
 apply(case_tac xs,simp add:cp_def)
prensani@13020
   737
 apply clarify
prensani@13020
   738
 apply (simp del:map.simps)
prensani@13020
   739
 apply(subgoal_tac "(map (lift Q) ((a, b) # list))\<noteq>[]")
nipkow@17588
   740
  apply(drule last_conv_nth)
prensani@13020
   741
  apply (simp del:map.simps)
prensani@13020
   742
  apply(simp only:last_lift_not_None)
prensani@13020
   743
 apply simp
prensani@13020
   744
--{* @{text "\<exists>i<length x. fst (x ! i) = Some Q"} *}
prensani@13020
   745
apply(erule exE)
prensani@13020
   746
apply(drule_tac n=i and P="\<lambda>i. i < length x \<and> fst (x ! i) = Some Q" in Ex_first_occurrence)
prensani@13020
   747
apply clarify
prensani@13020
   748
apply (simp add:cp_def)
prensani@13020
   749
 apply clarify
prensani@13020
   750
 apply(frule_tac i=m in Seq_sound2,force)
prensani@13020
   751
  apply simp+
prensani@13020
   752
apply clarify
prensani@13020
   753
apply(simp add:comm_def)
prensani@13020
   754
apply(erule_tac x=s in allE)
prensani@13020
   755
apply(drule_tac c=xs in subsetD,simp)
prensani@13020
   756
 apply(case_tac "xs=[]",simp)
prensani@13020
   757
 apply(simp add:cp_def assum_def nth_append)
prensani@13020
   758
 apply clarify
prensani@13020
   759
 apply(erule_tac x=i in allE)
prensani@13020
   760
  back 
prensani@13020
   761
 apply(simp add:snd_lift)
prensani@13020
   762
 apply(erule mp)
berghofe@23746
   763
 apply(force elim:etranE intro:Env simp add:lift_def)
prensani@13020
   764
apply simp
prensani@13020
   765
apply clarify
prensani@13020
   766
apply(erule_tac x="snd(xs!m)" in allE)
prensani@13020
   767
apply(drule_tac c=ys in subsetD,simp add:cp_def assum_def)
prensani@13020
   768
 apply(case_tac "xs\<noteq>[]")
nipkow@17588
   769
 apply(drule last_conv_nth,simp)
prensani@13020
   770
 apply(rule conjI)
prensani@13020
   771
  apply(erule mp)
prensani@13020
   772
  apply(case_tac "xs!m")
prensani@13020
   773
  apply(case_tac "fst(xs!m)",simp)
prensani@13020
   774
  apply(simp add:lift_def nth_append)
prensani@13020
   775
 apply clarify
prensani@13020
   776
 apply(erule_tac x="m+i" in allE)
prensani@13020
   777
 back
prensani@13020
   778
 back
prensani@13020
   779
 apply(case_tac ys,(simp add:nth_append)+)
prensani@13020
   780
 apply (case_tac i, (simp add:snd_lift)+)
prensani@13020
   781
  apply(erule mp)
prensani@13020
   782
  apply(case_tac "xs!m")
berghofe@23746
   783
  apply(force elim:etran.cases intro:Env simp add:lift_def)
prensani@13020
   784
 apply simp 
prensani@13020
   785
apply simp
prensani@13020
   786
apply clarify
prensani@13020
   787
apply(rule conjI,clarify)
prensani@13020
   788
 apply(case_tac "i<m",simp add:nth_append)
prensani@13020
   789
  apply(simp add:snd_lift)
prensani@13020
   790
  apply(erule allE, erule impE, assumption, erule mp)
prensani@13020
   791
  apply(case_tac "(xs ! i)")
prensani@13020
   792
  apply(case_tac "(xs ! Suc i)")   
prensani@13020
   793
  apply(case_tac "fst(xs ! i)",force simp add:lift_def)   
prensani@13020
   794
  apply(case_tac "fst(xs ! Suc i)")
prensani@13020
   795
   apply (force simp add:lift_def)
prensani@13020
   796
  apply (force simp add:lift_def)
prensani@13020
   797
 apply(erule_tac x="i-m" in allE) 
prensani@13020
   798
 back
prensani@13020
   799
 back
prensani@13020
   800
 apply(subgoal_tac "Suc (i - m) < length ys",simp)
prensani@13020
   801
  prefer 2
prensani@13020
   802
  apply arith
prensani@13020
   803
 apply(simp add:nth_append snd_lift)
prensani@13020
   804
 apply(rule conjI,clarify)
prensani@13020
   805
  apply(subgoal_tac "i=m")
prensani@13020
   806
   prefer 2
prensani@13020
   807
   apply arith
prensani@13020
   808
  apply clarify
prensani@13020
   809
  apply(simp add:cp_def)
prensani@13020
   810
  apply(rule tl_zero)
prensani@13020
   811
    apply(erule mp)
prensani@13020
   812
    apply(case_tac "lift Q (xs!m)",simp add:snd_lift)
prensani@13020
   813
    apply(case_tac "xs!m",case_tac "fst(xs!m)",simp add:lift_def snd_lift)
prensani@13020
   814
     apply(case_tac ys,simp+)
prensani@13020
   815
    apply(simp add:lift_def)
prensani@13020
   816
   apply simp 
prensani@13020
   817
  apply force
prensani@13020
   818
 apply clarify
prensani@13020
   819
 apply(rule tl_zero)
prensani@13020
   820
   apply(rule tl_zero)
prensani@13020
   821
     apply (subgoal_tac "i-m=Suc(i-Suc m)")
prensani@13020
   822
      apply simp
prensani@13020
   823
      apply(erule mp)
prensani@13020
   824
      apply(case_tac ys,simp+)
prensani@13020
   825
   apply force
prensani@13020
   826
  apply arith
prensani@13020
   827
 apply force
prensani@13020
   828
apply clarify
prensani@13020
   829
apply(case_tac "(map (lift Q) xs @ tl ys)\<noteq>[]")
nipkow@17588
   830
 apply(drule last_conv_nth)
prensani@13020
   831
 apply(simp add: snd_lift nth_append)
prensani@13020
   832
 apply(rule conjI,clarify)
prensani@13020
   833
  apply(case_tac ys,simp+)
prensani@13020
   834
 apply clarify
prensani@13020
   835
 apply(case_tac ys,simp+)
prensani@13020
   836
done
prensani@13020
   837
prensani@13020
   838
subsubsection{* Soundness of the While rule *}
prensani@13020
   839
prensani@13020
   840
lemma last_append[rule_format]:
prensani@13020
   841
  "\<forall>xs. ys\<noteq>[] \<longrightarrow> ((xs@ys)!(length (xs@ys) - (Suc 0)))=(ys!(length ys - (Suc 0)))"
prensani@13020
   842
apply(induct ys)
prensani@13020
   843
 apply simp
prensani@13020
   844
apply clarify
prensani@13020
   845
apply (simp add:nth_append length_append)
prensani@13020
   846
done
prensani@13020
   847
prensani@13020
   848
lemma assum_after_body: 
prensani@13020
   849
  "\<lbrakk> \<Turnstile> P sat [pre \<inter> b, rely, guar, pre]; 
prensani@13020
   850
  (Some P, s) # xs \<in> cptn_mod; fst (last ((Some P, s) # xs)) = None; s \<in> b;
prensani@13022
   851
  (Some (While b P), s) # (Some (Seq P (While b P)), s) # 
prensani@13022
   852
   map (lift (While b P)) xs @ ys \<in> assum (pre, rely)\<rbrakk>
prensani@13020
   853
  \<Longrightarrow> (Some (While b P), snd (last ((Some P, s) # xs))) # ys \<in> assum (pre, rely)"
prensani@13020
   854
apply(simp add:assum_def com_validity_def cp_def cptn_iff_cptn_mod)
prensani@13020
   855
apply clarify
prensani@13020
   856
apply(erule_tac x=s in allE)
prensani@13020
   857
apply(drule_tac c="(Some P, s) # xs" in subsetD,simp)
prensani@13020
   858
 apply clarify
prensani@13020
   859
 apply(erule_tac x="Suc i" in allE)
prensani@13020
   860
 apply simp
prensani@13020
   861
 apply(simp add:Cons_lift_append nth_append snd_lift del:map.simps)
prensani@13020
   862
 apply(erule mp)
berghofe@23746
   863
 apply(erule etranE,simp)
prensani@13020
   864
 apply(case_tac "fst(((Some P, s) # xs) ! i)")
prensani@13020
   865
  apply(force intro:Env simp add:lift_def)
prensani@13020
   866
 apply(force intro:Env simp add:lift_def)
prensani@13020
   867
apply(rule conjI)
prensani@13020
   868
 apply clarify
prensani@13020
   869
 apply(simp add:comm_def last_length)
prensani@13020
   870
apply clarify
prensani@13020
   871
apply(rule conjI)
prensani@13020
   872
 apply(simp add:comm_def)
prensani@13020
   873
apply clarify
prensani@13020
   874
apply(erule_tac x="Suc(length xs + i)" in allE,simp)
nipkow@41842
   875
apply(case_tac i, simp add:nth_append Cons_lift_append snd_lift last_conv_nth lift_def split_def)
nipkow@41842
   876
apply(simp add:Cons_lift_append nth_append snd_lift)
prensani@13020
   877
done
prensani@13020
   878
prensani@13020
   879
lemma While_sound_aux [rule_format]: 
prensani@13020
   880
  "\<lbrakk> pre \<inter> - b \<subseteq> post; \<Turnstile> P sat [pre \<inter> b, rely, guar, pre]; \<forall>s. (s, s) \<in> guar;
prensani@13020
   881
   stable pre rely;  stable post rely; x \<in> cptn_mod \<rbrakk> 
prensani@13020
   882
  \<Longrightarrow>  \<forall>s xs. x=(Some(While b P),s)#xs \<longrightarrow> x\<in>assum(pre, rely) \<longrightarrow> x \<in> comm (guar, post)"
prensani@13020
   883
apply(erule cptn_mod.induct)
prensani@13020
   884
apply safe
prensani@13020
   885
apply (simp_all del:last.simps)
prensani@13020
   886
--{* 5 subgoals left *}
prensani@13020
   887
apply(simp add:comm_def)
prensani@13020
   888
--{* 4 subgoals left *}
prensani@13020
   889
apply(rule etran_in_comm)
prensani@13020
   890
apply(erule mp)
prensani@13020
   891
apply(erule tl_of_assum_in_assum,simp)
prensani@13020
   892
--{* While-None *}
berghofe@23746
   893
apply(ind_cases "((Some (While b P), s), None, t) \<in> ctran" for s t)
prensani@13020
   894
apply(simp add:comm_def)
prensani@13020
   895
apply(simp add:cptn_iff_cptn_mod [THEN sym])
prensani@13020
   896
apply(rule conjI,clarify)
prensani@13020
   897
 apply(force simp add:assum_def)
prensani@13020
   898
apply clarify
prensani@13020
   899
apply(rule conjI, clarify)
prensani@13020
   900
 apply(case_tac i,simp,simp)
prensani@13020
   901
 apply(force simp add:not_ctran_None2)
berghofe@23746
   902
apply(subgoal_tac "\<forall>i. Suc i < length ((None, t) # xs) \<longrightarrow> (((None, t) # xs) ! i, ((None, t) # xs) ! Suc i)\<in> etran")
prensani@13020
   903
 prefer 2
prensani@13020
   904
 apply clarify
prensani@13020
   905
 apply(rule_tac m="length ((None, s) # xs)" in etran_or_ctran,simp+)
prensani@13020
   906
 apply(erule not_ctran_None2,simp)
prensani@13020
   907
 apply simp+
prensani@13020
   908
apply(frule_tac j="0" and k="length ((None, s) # xs) - 1" and p=post in stability,simp+)
prensani@13020
   909
   apply(force simp add:assum_def subsetD)
prensani@13020
   910
  apply(simp add:assum_def)
prensani@13020
   911
  apply clarify
prensani@13020
   912
  apply(erule_tac x="i" in allE,simp) 
prensani@13020
   913
  apply(erule_tac x="Suc i" in allE,simp) 
prensani@13020
   914
 apply simp
prensani@13020
   915
apply clarify
prensani@13020
   916
apply (simp add:last_length)
prensani@13020
   917
--{* WhileOne *}
prensani@13020
   918
apply(thin_tac "P = While b P \<longrightarrow> ?Q")
prensani@13020
   919
apply(rule ctran_in_comm,simp)
prensani@13020
   920
apply(simp add:Cons_lift del:map.simps)
prensani@13020
   921
apply(simp add:comm_def del:map.simps)
prensani@13020
   922
apply(rule conjI)
prensani@13020
   923
 apply clarify
prensani@13020
   924
 apply(case_tac "fst(((Some P, sa) # xs) ! i)")
prensani@13020
   925
  apply(case_tac "((Some P, sa) # xs) ! i")
prensani@13020
   926
  apply (simp add:lift_def)
berghofe@23746
   927
  apply(ind_cases "(Some (While b P), ba) -c\<rightarrow> t" for ba t)
prensani@13020
   928
   apply simp
prensani@13020
   929
  apply simp
prensani@13020
   930
 apply(simp add:snd_lift del:map.simps)
prensani@13020
   931
 apply(simp only:com_validity_def cp_def cptn_iff_cptn_mod)
prensani@13020
   932
 apply(erule_tac x=sa in allE)
prensani@13020
   933
 apply(drule_tac c="(Some P, sa) # xs" in subsetD)
prensani@13020
   934
  apply (simp add:assum_def del:map.simps)
prensani@13020
   935
  apply clarify
prensani@13020
   936
  apply(erule_tac x="Suc ia" in allE,simp add:snd_lift del:map.simps)
prensani@13020
   937
  apply(erule mp)
prensani@13020
   938
  apply(case_tac "fst(((Some P, sa) # xs) ! ia)")
berghofe@23746
   939
   apply(erule etranE,simp add:lift_def)
prensani@13020
   940
   apply(rule Env)
berghofe@23746
   941
  apply(erule etranE,simp add:lift_def)
prensani@13020
   942
  apply(rule Env)
prensani@13020
   943
 apply (simp add:comm_def del:map.simps)
prensani@13020
   944
 apply clarify
prensani@13020
   945
 apply(erule allE,erule impE,assumption)
prensani@13020
   946
 apply(erule mp)
prensani@13020
   947
 apply(case_tac "((Some P, sa) # xs) ! i")
prensani@13020
   948
 apply(case_tac "xs!i")
prensani@13020
   949
 apply(simp add:lift_def)
prensani@13020
   950
 apply(case_tac "fst(xs!i)")
prensani@13020
   951
  apply force
prensani@13020
   952
 apply force
prensani@13020
   953
--{* last=None *}
prensani@13020
   954
apply clarify
prensani@13020
   955
apply(subgoal_tac "(map (lift (While b P)) ((Some P, sa) # xs))\<noteq>[]")
nipkow@17588
   956
 apply(drule last_conv_nth)
prensani@13020
   957
 apply (simp del:map.simps)
prensani@13020
   958
 apply(simp only:last_lift_not_None)
prensani@13020
   959
apply simp
prensani@13020
   960
--{* WhileMore *}
prensani@13020
   961
apply(thin_tac "P = While b P \<longrightarrow> ?Q")
prensani@13020
   962
apply(rule ctran_in_comm,simp del:last.simps)
prensani@13020
   963
--{* metiendo la hipotesis antes de dividir la conclusion. *}
prensani@13020
   964
apply(subgoal_tac "(Some (While b P), snd (last ((Some P, sa) # xs))) # ys \<in> assum (pre, rely)")
prensani@13020
   965
 apply (simp del:last.simps)
prensani@13020
   966
 prefer 2
prensani@13020
   967
 apply(erule assum_after_body)
prensani@13020
   968
  apply (simp del:last.simps)+
prensani@13020
   969
--{* lo de antes. *}
prensani@13020
   970
apply(simp add:comm_def del:map.simps last.simps)
prensani@13020
   971
apply(rule conjI)
prensani@13020
   972
 apply clarify
prensani@13020
   973
 apply(simp only:Cons_lift_append)
prensani@13020
   974
 apply(case_tac "i<length xs")
prensani@13020
   975
  apply(simp add:nth_append del:map.simps last.simps)
prensani@13020
   976
  apply(case_tac "fst(((Some P, sa) # xs) ! i)")
prensani@13020
   977
   apply(case_tac "((Some P, sa) # xs) ! i")
prensani@13020
   978
   apply (simp add:lift_def del:last.simps)
berghofe@23746
   979
   apply(ind_cases "(Some (While b P), ba) -c\<rightarrow> t" for ba t)
prensani@13020
   980
    apply simp
prensani@13020
   981
   apply simp
prensani@13020
   982
  apply(simp add:snd_lift del:map.simps last.simps)
prensani@13020
   983
  apply(thin_tac " \<forall>i. i < length ys \<longrightarrow> ?P i")
prensani@13020
   984
  apply(simp only:com_validity_def cp_def cptn_iff_cptn_mod)
prensani@13020
   985
  apply(erule_tac x=sa in allE)
prensani@13020
   986
  apply(drule_tac c="(Some P, sa) # xs" in subsetD)
prensani@13020
   987
   apply (simp add:assum_def del:map.simps last.simps)
prensani@13020
   988
   apply clarify
prensani@13020
   989
   apply(erule_tac x="Suc ia" in allE,simp add:nth_append snd_lift del:map.simps last.simps, erule mp)
prensani@13020
   990
   apply(case_tac "fst(((Some P, sa) # xs) ! ia)")
berghofe@23746
   991
    apply(erule etranE,simp add:lift_def)
prensani@13020
   992
    apply(rule Env)
berghofe@23746
   993
   apply(erule etranE,simp add:lift_def)
prensani@13020
   994
   apply(rule Env)
prensani@13020
   995
  apply (simp add:comm_def del:map.simps)
prensani@13020
   996
  apply clarify
prensani@13020
   997
  apply(erule allE,erule impE,assumption)
prensani@13020
   998
  apply(erule mp)
prensani@13020
   999
  apply(case_tac "((Some P, sa) # xs) ! i")
prensani@13020
  1000
  apply(case_tac "xs!i")
prensani@13020
  1001
  apply(simp add:lift_def)
prensani@13020
  1002
  apply(case_tac "fst(xs!i)")
prensani@13020
  1003
   apply force
prensani@13020
  1004
 apply force
prensani@13020
  1005
--{*  @{text "i \<ge> length xs"} *}
prensani@13020
  1006
apply(subgoal_tac "i-length xs <length ys") 
prensani@13020
  1007
 prefer 2
prensani@13020
  1008
 apply arith
prensani@13020
  1009
apply(erule_tac x="i-length xs" in allE,clarify)
prensani@13020
  1010
apply(case_tac "i=length xs")
prensani@13020
  1011
 apply (simp add:nth_append snd_lift del:map.simps last.simps)
prensani@13020
  1012
 apply(simp add:last_length del:last.simps)
prensani@13020
  1013
 apply(erule mp)
prensani@13020
  1014
 apply(case_tac "last((Some P, sa) # xs)")
prensani@13020
  1015
 apply(simp add:lift_def del:last.simps)
prensani@13020
  1016
--{* @{text "i>length xs"} *} 
prensani@13020
  1017
apply(case_tac "i-length xs")
prensani@13020
  1018
 apply arith
prensani@13020
  1019
apply(simp add:nth_append del:map.simps last.simps)
nipkow@13187
  1020
apply(rotate_tac -3)
prensani@13020
  1021
apply(subgoal_tac "i- Suc (length xs)=nat")
prensani@13020
  1022
 prefer 2
prensani@13020
  1023
 apply arith
prensani@13020
  1024
apply simp
prensani@13020
  1025
--{* last=None *}
prensani@13020
  1026
apply clarify
prensani@13020
  1027
apply(case_tac ys)
prensani@13020
  1028
 apply(simp add:Cons_lift del:map.simps last.simps)
prensani@13020
  1029
 apply(subgoal_tac "(map (lift (While b P)) ((Some P, sa) # xs))\<noteq>[]")
nipkow@17588
  1030
  apply(drule last_conv_nth)
prensani@13020
  1031
  apply (simp del:map.simps)
prensani@13020
  1032
  apply(simp only:last_lift_not_None)
prensani@13020
  1033
 apply simp
prensani@13020
  1034
apply(subgoal_tac "((Some (Seq P (While b P)), sa) # map (lift (While b P)) xs @ ys)\<noteq>[]")
nipkow@17588
  1035
 apply(drule last_conv_nth)
prensani@13020
  1036
 apply (simp del:map.simps last.simps)
prensani@13020
  1037
 apply(simp add:nth_append del:last.simps)
prensani@13020
  1038
 apply(subgoal_tac "((Some (While b P), snd (last ((Some P, sa) # xs))) # a # list)\<noteq>[]")
nipkow@17588
  1039
  apply(drule last_conv_nth)
prensani@13020
  1040
  apply (simp del:map.simps last.simps)
prensani@13020
  1041
 apply simp
prensani@13020
  1042
apply simp
prensani@13020
  1043
done
prensani@13020
  1044
prensani@13020
  1045
lemma While_sound: 
prensani@13020
  1046
  "\<lbrakk>stable pre rely; pre \<inter> - b \<subseteq> post; stable post rely;
prensani@13020
  1047
    \<Turnstile> P sat [pre \<inter> b, rely, guar, pre]; \<forall>s. (s,s)\<in>guar\<rbrakk>
prensani@13020
  1048
  \<Longrightarrow> \<Turnstile> While b P sat [pre, rely, guar, post]"
prensani@13020
  1049
apply(unfold com_validity_def)
prensani@13020
  1050
apply clarify
prensani@13020
  1051
apply(erule_tac xs="tl x" in While_sound_aux)
prensani@13020
  1052
 apply(simp add:com_validity_def)
prensani@13020
  1053
 apply force
prensani@13020
  1054
 apply simp_all
prensani@13020
  1055
apply(simp add:cptn_iff_cptn_mod cp_def)
prensani@13020
  1056
apply(simp add:cp_def)
prensani@13020
  1057
apply clarify
prensani@13020
  1058
apply(rule nth_equalityI)
prensani@13020
  1059
 apply simp_all
prensani@13020
  1060
 apply(case_tac x,simp+)
prensani@13020
  1061
apply clarify
prensani@13020
  1062
apply(case_tac i,simp+)
prensani@13020
  1063
apply(case_tac x,simp+)
prensani@13020
  1064
done
prensani@13020
  1065
prensani@13020
  1066
subsubsection{* Soundness of the Rule of Consequence *}
prensani@13020
  1067
prensani@13020
  1068
lemma Conseq_sound: 
prensani@13020
  1069
  "\<lbrakk>pre \<subseteq> pre'; rely \<subseteq> rely'; guar' \<subseteq> guar; post' \<subseteq> post; 
prensani@13020
  1070
  \<Turnstile> P sat [pre', rely', guar', post']\<rbrakk>
prensani@13020
  1071
  \<Longrightarrow> \<Turnstile> P sat [pre, rely, guar, post]"
prensani@13020
  1072
apply(simp add:com_validity_def assum_def comm_def)
prensani@13020
  1073
apply clarify
prensani@13020
  1074
apply(erule_tac x=s in allE)
prensani@13020
  1075
apply(drule_tac c=x in subsetD)
prensani@13020
  1076
 apply force
prensani@13020
  1077
apply force
prensani@13020
  1078
done
prensani@13020
  1079
prensani@13020
  1080
subsubsection {* Soundness of the system for sequential component programs *}
prensani@13020
  1081
prensani@13020
  1082
theorem rgsound: 
prensani@13020
  1083
  "\<turnstile> P sat [pre, rely, guar, post] \<Longrightarrow> \<Turnstile> P sat [pre, rely, guar, post]"
prensani@13020
  1084
apply(erule rghoare.induct)
prensani@13020
  1085
 apply(force elim:Basic_sound)
prensani@13020
  1086
 apply(force elim:Seq_sound)
prensani@13020
  1087
 apply(force elim:Cond_sound)
prensani@13020
  1088
 apply(force elim:While_sound)
prensani@13020
  1089
 apply(force elim:Await_sound)
prensani@13020
  1090
apply(erule Conseq_sound,simp+)
prensani@13020
  1091
done     
prensani@13020
  1092
prensani@13020
  1093
subsection {* Soundness of the System for Parallel Programs *}
prensani@13020
  1094
haftmann@35416
  1095
definition ParallelCom :: "('a rgformula) list \<Rightarrow> 'a par_com" where
prensani@13020
  1096
  "ParallelCom Ps \<equiv> map (Some \<circ> fst) Ps" 
prensani@13020
  1097
prensani@13020
  1098
lemma two: 
prensani@13022
  1099
  "\<lbrakk> \<forall>i<length xs. rely \<union> (\<Union>j\<in>{j. j < length xs \<and> j \<noteq> i}. Guar (xs ! j)) 
prensani@13022
  1100
     \<subseteq> Rely (xs ! i);
prensani@13022
  1101
   pre \<subseteq> (\<Inter>i\<in>{i. i < length xs}. Pre (xs ! i));
prensani@13022
  1102
   \<forall>i<length xs. 
prensani@13022
  1103
   \<Turnstile> Com (xs ! i) sat [Pre (xs ! i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i)];
prensani@13022
  1104
   length xs=length clist; x \<in> par_cp (ParallelCom xs) s; x\<in>par_assum(pre, rely);
prensani@13020
  1105
  \<forall>i<length clist. clist!i\<in>cp (Some(Com(xs!i))) s; x \<propto> clist \<rbrakk>
prensani@13020
  1106
  \<Longrightarrow> \<forall>j i. i<length clist \<and> Suc j<length x \<longrightarrow> (clist!i!j) -c\<rightarrow> (clist!i!Suc j) 
prensani@13020
  1107
  \<longrightarrow> (snd(clist!i!j), snd(clist!i!Suc j)) \<in> Guar(xs!i)"
prensani@13020
  1108
apply(unfold par_cp_def)
paulson@15102
  1109
apply (rule ccontr) 
prensani@13020
  1110
--{* By contradiction: *}
paulson@15102
  1111
apply (simp del: Un_subset_iff)
prensani@13020
  1112
apply(erule exE)
prensani@13020
  1113
--{* the first c-tran that does not satisfy the guarantee-condition is from @{text "\<sigma>_i"} at step @{text "m"}. *}
prensani@13020
  1114
apply(drule_tac n=j and P="\<lambda>j. \<exists>i. ?H i j" in Ex_first_occurrence)
prensani@13020
  1115
apply(erule exE)
prensani@13020
  1116
apply clarify
prensani@13020
  1117
--{* @{text "\<sigma>_i \<in> A(pre, rely_1)"} *}
prensani@13020
  1118
apply(subgoal_tac "take (Suc (Suc m)) (clist!i) \<in> assum(Pre(xs!i), Rely(xs!i))")
prensani@13020
  1119
--{* but this contradicts @{text "\<Turnstile> \<sigma>_i sat [pre_i,rely_i,guar_i,post_i]"} *}
prensani@13020
  1120
 apply(erule_tac x=i and P="\<lambda>i. ?H i \<longrightarrow> \<Turnstile> (?J i) sat [?I i,?K i,?M i,?N i]" in allE,erule impE,assumption)
prensani@13020
  1121
 apply(simp add:com_validity_def)
prensani@13020
  1122
 apply(erule_tac x=s in allE)
prensani@13020
  1123
 apply(simp add:cp_def comm_def)
prensani@13020
  1124
 apply(drule_tac c="take (Suc (Suc m)) (clist ! i)" in subsetD)
prensani@13020
  1125
  apply simp
paulson@15102
  1126
  apply (blast intro: takecptn_is_cptn) 
prensani@13020
  1127
 apply simp
prensani@13020
  1128
 apply clarify
prensani@13020
  1129
 apply(erule_tac x=m and P="\<lambda>j. ?I j \<and> ?J j \<longrightarrow> ?H j" in allE)
prensani@13020
  1130
 apply (simp add:conjoin_def same_length_def)
paulson@15102
  1131
apply(simp add:assum_def del: Un_subset_iff)
prensani@13020
  1132
apply(rule conjI)
prensani@13020
  1133
 apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow>  ?I j \<in>cp (?K j) (?J j)" in allE)
prensani@13020
  1134
 apply(simp add:cp_def par_assum_def)
prensani@13020
  1135
 apply(drule_tac c="s" in subsetD,simp)
prensani@13020
  1136
 apply simp
prensani@13020
  1137
apply clarify
prensani@13020
  1138
apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> ?M \<union> UNION (?S j) (?T j) \<subseteq>  (?L j)" in allE)
paulson@15102
  1139
apply(simp del: Un_subset_iff)
prensani@13020
  1140
apply(erule subsetD)
prensani@13020
  1141
apply simp
prensani@13020
  1142
apply(simp add:conjoin_def compat_label_def)
prensani@13020
  1143
apply clarify
prensani@13020
  1144
apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> (?P j) \<or> ?Q j" in allE,simp)
prensani@13020
  1145
--{* each etran in @{text "\<sigma>_1[0\<dots>m]"} corresponds to  *}
prensani@13020
  1146
apply(erule disjE)
prensani@13020
  1147
--{* a c-tran in some @{text "\<sigma>_{ib}"}  *}
prensani@13020
  1148
 apply clarify
prensani@13020
  1149
 apply(case_tac "i=ib",simp)
berghofe@23746
  1150
  apply(erule etranE,simp)
berghofe@13601
  1151
 apply(erule_tac x="ib" and P="\<lambda>i. ?H i \<longrightarrow> (?I i) \<or> (?J i)" in allE)
berghofe@23746
  1152
 apply (erule etranE)
prensani@13020
  1153
 apply(case_tac "ia=m",simp)
berghofe@13601
  1154
 apply simp
prensani@13020
  1155
 apply(erule_tac x=ia and P="\<lambda>j. ?H j \<longrightarrow> (\<forall> i. ?P i j)" in allE)
prensani@13020
  1156
 apply(subgoal_tac "ia<m",simp)
prensani@13020
  1157
  prefer 2
prensani@13020
  1158
  apply arith
prensani@13020
  1159
 apply(erule_tac x=ib and P="\<lambda>j. (?I j, ?H j)\<in> ctran \<longrightarrow> (?P i j)" in allE,simp)
prensani@13020
  1160
 apply(simp add:same_state_def)
berghofe@13601
  1161
 apply(erule_tac x=i and P="\<lambda>j. (?T j) \<longrightarrow> (\<forall>i. (?H j i) \<longrightarrow> (snd (?d j i))=(snd (?e j i)))" in all_dupE)
prensani@13020
  1162
 apply(erule_tac x=ib and P="\<lambda>j. (?T j) \<longrightarrow> (\<forall>i. (?H j i) \<longrightarrow> (snd (?d j i))=(snd (?e j i)))" in allE,simp)
prensani@13020
  1163
--{* or an e-tran in @{text "\<sigma>"}, 
prensani@13020
  1164
therefore it satisfies @{text "rely \<or> guar_{ib}"} *}
prensani@13020
  1165
apply (force simp add:par_assum_def same_state_def)
prensani@13020
  1166
done
prensani@13020
  1167
paulson@15102
  1168
prensani@13020
  1169
lemma three [rule_format]: 
prensani@13022
  1170
  "\<lbrakk> xs\<noteq>[]; \<forall>i<length xs. rely \<union> (\<Union>j\<in>{j. j < length xs \<and> j \<noteq> i}. Guar (xs ! j)) 
prensani@13022
  1171
   \<subseteq> Rely (xs ! i);
prensani@13022
  1172
   pre \<subseteq> (\<Inter>i\<in>{i. i < length xs}. Pre (xs ! i));
prensani@13022
  1173
   \<forall>i<length xs. 
prensani@13022
  1174
    \<Turnstile> Com (xs ! i) sat [Pre (xs ! i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i)];
prensani@13022
  1175
   length xs=length clist; x \<in> par_cp (ParallelCom xs) s; x \<in> par_assum(pre, rely);
prensani@13020
  1176
  \<forall>i<length clist. clist!i\<in>cp (Some(Com(xs!i))) s; x \<propto> clist \<rbrakk>
prensani@13020
  1177
  \<Longrightarrow> \<forall>j i. i<length clist \<and> Suc j<length x \<longrightarrow> (clist!i!j) -e\<rightarrow> (clist!i!Suc j) 
prensani@13020
  1178
  \<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))"
prensani@13020
  1179
apply(drule two)
prensani@13020
  1180
 apply simp_all
prensani@13020
  1181
apply clarify
prensani@13020
  1182
apply(simp add:conjoin_def compat_label_def)
prensani@13020
  1183
apply clarify
prensani@13020
  1184
apply(erule_tac x=j and P="\<lambda>j. ?H j \<longrightarrow> (?J j \<and> (\<exists>i. ?P i j)) \<or> ?I j" in allE,simp)
prensani@13020
  1185
apply(erule disjE)
prensani@13020
  1186
 prefer 2
prensani@13020
  1187
 apply(force simp add:same_state_def par_assum_def)
prensani@13020
  1188
apply clarify
prensani@13020
  1189
apply(case_tac "i=ia",simp)
berghofe@23746
  1190
 apply(erule etranE,simp)
prensani@13020
  1191
apply(erule_tac x="ia" and P="\<lambda>i. ?H i \<longrightarrow> (?I i) \<or> (?J i)" in allE,simp)
prensani@13020
  1192
apply(erule_tac x=j and P="\<lambda>j. \<forall>i. ?S j i \<longrightarrow> (?I j i, ?H j i)\<in> ctran \<longrightarrow> (?P i j)" in allE)
prensani@13020
  1193
apply(erule_tac x=ia and P="\<lambda>j. ?S j \<longrightarrow> (?I j, ?H j)\<in> ctran \<longrightarrow> (?P j)" in allE)
prensani@13020
  1194
apply(simp add:same_state_def)
berghofe@13601
  1195
apply(erule_tac x=i and P="\<lambda>j. (?T j) \<longrightarrow> (\<forall>i. (?H j i) \<longrightarrow> (snd (?d j i))=(snd (?e j i)))" in all_dupE)
prensani@13020
  1196
apply(erule_tac x=ia and P="\<lambda>j. (?T j) \<longrightarrow> (\<forall>i. (?H j i) \<longrightarrow> (snd (?d j i))=(snd (?e j i)))" in allE,simp)
prensani@13020
  1197
done
prensani@13020
  1198
prensani@13020
  1199
lemma four: 
prensani@13022
  1200
  "\<lbrakk>xs\<noteq>[]; \<forall>i < length xs. rely \<union> (\<Union>j\<in>{j. j < length xs \<and> j \<noteq> i}. Guar (xs ! j)) 
prensani@13022
  1201
    \<subseteq> Rely (xs ! i);
prensani@13022
  1202
   (\<Union>j\<in>{j. j < length xs}. Guar (xs ! j)) \<subseteq> guar; 
prensani@13022
  1203
   pre \<subseteq> (\<Inter>i\<in>{i. i < length xs}. Pre (xs ! i));
prensani@13022
  1204
   \<forall>i < length xs.
prensani@13022
  1205
    \<Turnstile> Com (xs ! i) sat [Pre (xs ! i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i)];
prensani@13022
  1206
   x \<in> par_cp (ParallelCom xs) s; x \<in> par_assum (pre, rely); Suc i < length x; 
prensani@13022
  1207
   x ! i -pc\<rightarrow> x ! Suc i\<rbrakk>
prensani@13020
  1208
  \<Longrightarrow> (snd (x ! i), snd (x ! Suc i)) \<in> guar"
paulson@15102
  1209
apply(simp add: ParallelCom_def del: Un_subset_iff)
prensani@13020
  1210
apply(subgoal_tac "(map (Some \<circ> fst) xs)\<noteq>[]")
prensani@13020
  1211
 prefer 2
prensani@13020
  1212
 apply simp
prensani@13020
  1213
apply(frule rev_subsetD)
prensani@13020
  1214
 apply(erule one [THEN equalityD1])
prensani@13020
  1215
apply(erule subsetD)
paulson@15102
  1216
apply (simp del: Un_subset_iff)
prensani@13020
  1217
apply clarify
prensani@13020
  1218
apply(drule_tac pre=pre and rely=rely and  x=x and s=s and xs=xs and clist=clist in two)
prensani@13020
  1219
apply(assumption+)
prensani@13020
  1220
     apply(erule sym)
prensani@13020
  1221
    apply(simp add:ParallelCom_def)
prensani@13020
  1222
   apply assumption
prensani@13020
  1223
  apply(simp add:Com_def)
prensani@13020
  1224
 apply assumption
prensani@13020
  1225
apply(simp add:conjoin_def same_program_def)
prensani@13020
  1226
apply clarify
prensani@13020
  1227
apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> fst(?I j)=(?J j)" in all_dupE)
prensani@13020
  1228
apply(erule_tac x="Suc i" and P="\<lambda>j. ?H j \<longrightarrow> fst(?I j)=(?J j)" in allE)
berghofe@23746
  1229
apply(erule par_ctranE,simp)
prensani@13020
  1230
apply(erule_tac x=i and P="\<lambda>j. \<forall>i. ?S j i \<longrightarrow> (?I j i, ?H j i)\<in> ctran \<longrightarrow> (?P i j)" in allE)
prensani@13020
  1231
apply(erule_tac x=ia and P="\<lambda>j. ?S j \<longrightarrow> (?I j, ?H j)\<in> ctran \<longrightarrow> (?P j)" in allE)
prensani@13020
  1232
apply(rule_tac x=ia in exI)
prensani@13020
  1233
apply(simp add:same_state_def)
prensani@13020
  1234
apply(erule_tac x=ia and P="\<lambda>j. (?T j) \<longrightarrow> (\<forall>i. (?H j i) \<longrightarrow> (snd (?d j i))=(snd (?e j i)))" in all_dupE,simp)
prensani@13020
  1235
apply(erule_tac x=ia and P="\<lambda>j. (?T j) \<longrightarrow> (\<forall>i. (?H j i) \<longrightarrow> (snd (?d j i))=(snd (?e j i)))" in allE,simp)
prensani@13020
  1236
apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in all_dupE)
prensani@13020
  1237
apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in all_dupE,simp)
prensani@13020
  1238
apply(erule_tac x="Suc i" and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE,simp)
prensani@13020
  1239
apply(erule mp)
prensani@13020
  1240
apply(subgoal_tac "r=fst(clist ! ia ! Suc i)",simp)
prensani@13020
  1241
apply(drule_tac i=ia in list_eq_if)
prensani@13020
  1242
back
prensani@13020
  1243
apply simp_all
prensani@13020
  1244
done
prensani@13020
  1245
prensani@13020
  1246
lemma parcptn_not_empty [simp]:"[] \<notin> par_cptn"
berghofe@23746
  1247
apply(force elim:par_cptn.cases)
prensani@13020
  1248
done
prensani@13020
  1249
prensani@13020
  1250
lemma five: 
prensani@13022
  1251
  "\<lbrakk>xs\<noteq>[]; \<forall>i<length xs. rely \<union> (\<Union>j\<in>{j. j < length xs \<and> j \<noteq> i}. Guar (xs ! j))
prensani@13022
  1252
   \<subseteq> Rely (xs ! i);
prensani@13022
  1253
   pre \<subseteq> (\<Inter>i\<in>{i. i < length xs}. Pre (xs ! i)); 
prensani@13022
  1254
   (\<Inter>i\<in>{i. i < length xs}. Post (xs ! i)) \<subseteq> post;
prensani@13022
  1255
   \<forall>i < length xs.
prensani@13022
  1256
    \<Turnstile> Com (xs ! i) sat [Pre (xs ! i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i)];
prensani@13022
  1257
    x \<in> par_cp (ParallelCom xs) s; x \<in> par_assum (pre, rely); 
prensani@13022
  1258
   All_None (fst (last x)) \<rbrakk> \<Longrightarrow> snd (last x) \<in> post"
paulson@15102
  1259
apply(simp add: ParallelCom_def del: Un_subset_iff)
prensani@13020
  1260
apply(subgoal_tac "(map (Some \<circ> fst) xs)\<noteq>[]")
prensani@13020
  1261
 prefer 2
prensani@13020
  1262
 apply simp
prensani@13020
  1263
apply(frule rev_subsetD)
prensani@13020
  1264
 apply(erule one [THEN equalityD1])
prensani@13020
  1265
apply(erule subsetD)
paulson@15102
  1266
apply(simp del: Un_subset_iff)
prensani@13020
  1267
apply clarify
prensani@13020
  1268
apply(subgoal_tac "\<forall>i<length clist. clist!i\<in>assum(Pre(xs!i), Rely(xs!i))")
prensani@13020
  1269
 apply(erule_tac x=i and P="\<lambda>i. ?H i \<longrightarrow> \<Turnstile> (?J i) sat [?I i,?K i,?M i,?N i]" in allE,erule impE,assumption)
prensani@13020
  1270
 apply(simp add:com_validity_def)
prensani@13020
  1271
 apply(erule_tac x=s in allE)
prensani@13020
  1272
 apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> (?I j) \<in> cp (?J j) s" in allE,simp)
prensani@13020
  1273
 apply(drule_tac c="clist!i" in subsetD)
prensani@13020
  1274
  apply (force simp add:Com_def)
prensani@13020
  1275
 apply(simp add:comm_def conjoin_def same_program_def del:last.simps)
prensani@13020
  1276
 apply clarify
prensani@13020
  1277
 apply(erule_tac x="length x - 1" and P="\<lambda>j. ?H j \<longrightarrow> fst(?I j)=(?J j)" in allE)
prensani@13020
  1278
 apply (simp add:All_None_def same_length_def)
prensani@13020
  1279
 apply(erule_tac x=i and P="\<lambda>j. ?H j \<longrightarrow> length(?J j)=(?K j)" in allE)
prensani@13020
  1280
 apply(subgoal_tac "length x - 1 < length x",simp)
prensani@13020
  1281
  apply(case_tac "x\<noteq>[]")
nipkow@17588
  1282
   apply(simp add: last_conv_nth)
prensani@13020
  1283
   apply(erule_tac x="clist!i" in ballE)
prensani@13020
  1284
    apply(simp add:same_state_def)
prensani@13020
  1285
    apply(subgoal_tac "clist!i\<noteq>[]")
nipkow@17588
  1286
     apply(simp add: last_conv_nth)
prensani@13020
  1287
    apply(case_tac x)
prensani@13020
  1288
     apply (force simp add:par_cp_def)
prensani@13020
  1289
    apply (force simp add:par_cp_def)
prensani@13020
  1290
   apply force
prensani@13020
  1291
  apply (force simp add:par_cp_def)
prensani@13020
  1292
 apply(case_tac x)
prensani@13020
  1293
  apply (force simp add:par_cp_def)
prensani@13020
  1294
 apply (force simp add:par_cp_def)
prensani@13020
  1295
apply clarify
prensani@13020
  1296
apply(simp add:assum_def)
prensani@13020
  1297
apply(rule conjI)
prensani@13020
  1298
 apply(simp add:conjoin_def same_state_def par_cp_def)
prensani@13020
  1299
 apply clarify
prensani@13020
  1300
 apply(erule_tac x=ia and P="\<lambda>j. (?T j) \<longrightarrow> (\<forall>i. (?H j i) \<longrightarrow> (snd (?d j i))=(snd (?e j i)))" in allE,simp)
prensani@13020
  1301
 apply(erule_tac x=0 and P="\<lambda>j. ?H j \<longrightarrow> (snd (?d j))=(snd (?e j))" in allE)
prensani@13020
  1302
 apply(case_tac x,simp+)
prensani@13020
  1303
 apply (simp add:par_assum_def)
prensani@13020
  1304
 apply clarify
prensani@13020
  1305
 apply(drule_tac c="snd (clist ! ia ! 0)" in subsetD)
prensani@13020
  1306
 apply assumption
prensani@13020
  1307
 apply simp
prensani@13020
  1308
apply clarify
prensani@13020
  1309
apply(erule_tac x=ia in all_dupE)
berghofe@13601
  1310
apply(rule subsetD, erule mp, assumption)
prensani@13020
  1311
apply(erule_tac pre=pre and rely=rely and x=x and s=s in  three)
prensani@13020
  1312
 apply(erule_tac x=ic in allE,erule mp)
prensani@13020
  1313
 apply simp_all
prensani@13020
  1314
 apply(simp add:ParallelCom_def)
prensani@13020
  1315
 apply(force simp add:Com_def)
prensani@13020
  1316
apply(simp add:conjoin_def same_length_def)
prensani@13020
  1317
done
prensani@13020
  1318
prensani@13020
  1319
lemma ParallelEmpty [rule_format]: 
prensani@13020
  1320
  "\<forall>i s. x \<in> par_cp (ParallelCom []) s \<longrightarrow> 
prensani@13020
  1321
  Suc i < length x \<longrightarrow> (x ! i, x ! Suc i) \<notin> par_ctran"
prensani@13020
  1322
apply(induct_tac x)
prensani@13020
  1323
 apply(simp add:par_cp_def ParallelCom_def)
prensani@13020
  1324
apply clarify
prensani@13020
  1325
apply(case_tac list,simp,simp)
prensani@13020
  1326
apply(case_tac i)
prensani@13020
  1327
 apply(simp add:par_cp_def ParallelCom_def)
berghofe@23746
  1328
 apply(erule par_ctranE,simp)
prensani@13020
  1329
apply(simp add:par_cp_def ParallelCom_def)
prensani@13020
  1330
apply clarify
berghofe@23746
  1331
apply(erule par_cptn.cases,simp)
prensani@13020
  1332
 apply simp
berghofe@23746
  1333
apply(erule par_ctranE)
prensani@13020
  1334
back
prensani@13020
  1335
apply simp
prensani@13020
  1336
done
prensani@13020
  1337
prensani@13020
  1338
theorem par_rgsound: 
prensani@13022
  1339
  "\<turnstile> c SAT [pre, rely, guar, post] \<Longrightarrow> 
prensani@13022
  1340
   \<Turnstile> (ParallelCom c) SAT [pre, rely, guar, post]"
prensani@13020
  1341
apply(erule par_rghoare.induct)
prensani@13020
  1342
apply(case_tac xs,simp)
prensani@13020
  1343
 apply(simp add:par_com_validity_def par_comm_def)
prensani@13020
  1344
 apply clarify
prensani@13020
  1345
 apply(case_tac "post=UNIV",simp)
prensani@13020
  1346
  apply clarify
prensani@13020
  1347
  apply(drule ParallelEmpty)
prensani@13020
  1348
   apply assumption
prensani@13020
  1349
  apply simp
prensani@13020
  1350
 apply clarify
prensani@13020
  1351
 apply simp
prensani@13020
  1352
apply(subgoal_tac "xs\<noteq>[]")
prensani@13020
  1353
 prefer 2
prensani@13020
  1354
 apply simp
prensani@13020
  1355
apply(thin_tac "xs = a # list")
prensani@13020
  1356
apply(simp add:par_com_validity_def par_comm_def)
prensani@13020
  1357
apply clarify
prensani@13020
  1358
apply(rule conjI)
prensani@13020
  1359
 apply clarify
prensani@13020
  1360
 apply(erule_tac pre=pre and rely=rely and guar=guar and x=x and s=s and xs=xs in four)
prensani@13020
  1361
        apply(assumption+)
prensani@13020
  1362
     apply clarify
prensani@13020
  1363
     apply (erule allE, erule impE, assumption,erule rgsound)
prensani@13020
  1364
    apply(assumption+)
prensani@13020
  1365
apply clarify
prensani@13020
  1366
apply(erule_tac pre=pre and rely=rely and post=post and x=x and s=s and xs=xs in five)
prensani@13020
  1367
      apply(assumption+)
prensani@13020
  1368
   apply clarify
prensani@13020
  1369
   apply (erule allE, erule impE, assumption,erule rgsound)
prensani@13020
  1370
  apply(assumption+) 
prensani@13020
  1371
done
prensani@13020
  1372
nipkow@13187
  1373
end