src/HOL/Hoare_Parallel/OG_Tactics.thy
author wenzelm
Thu May 24 17:25:53 2012 +0200 (2012-05-24)
changeset 47988 e4b69e10b990
parent 44928 7ef6505bde7f
child 51717 9e7d1c139569
permissions -rw-r--r--
tuned proofs;
prensani@13020
     1
header {* \section{Generation of Verification Conditions} *}
prensani@13020
     2
haftmann@27104
     3
theory OG_Tactics
haftmann@27104
     4
imports OG_Hoare
nipkow@15425
     5
begin
prensani@13020
     6
prensani@13020
     7
lemmas ann_hoare_intros=AnnBasic AnnSeq AnnCond1 AnnCond2 AnnWhile AnnAwait AnnConseq
prensani@13020
     8
lemmas oghoare_intros=Parallel Basic Seq Cond While Conseq
prensani@13020
     9
prensani@13020
    10
lemma ParallelConseqRule: 
prensani@13020
    11
 "\<lbrakk> p \<subseteq> (\<Inter>i\<in>{i. i<length Ts}. pre(the(com(Ts ! i))));  
prensani@13020
    12
  \<parallel>- (\<Inter>i\<in>{i. i<length Ts}. pre(the(com(Ts ! i)))) 
prensani@13020
    13
      (Parallel Ts) 
prensani@13020
    14
     (\<Inter>i\<in>{i. i<length Ts}. post(Ts ! i));  
prensani@13020
    15
  (\<Inter>i\<in>{i. i<length Ts}. post(Ts ! i)) \<subseteq> q \<rbrakk>  
prensani@13020
    16
  \<Longrightarrow> \<parallel>- p (Parallel Ts) q"
prensani@13020
    17
apply (rule Conseq)
prensani@13020
    18
prefer 2 
prensani@13020
    19
 apply fast
prensani@13020
    20
apply assumption+
prensani@13020
    21
done
prensani@13020
    22
prensani@13020
    23
lemma SkipRule: "p \<subseteq> q \<Longrightarrow> \<parallel>- p (Basic id) q"
prensani@13020
    24
apply(rule oghoare_intros)
prensani@13020
    25
  prefer 2 apply(rule Basic)
prensani@13020
    26
 prefer 2 apply(rule subset_refl)
prensani@13020
    27
apply(simp add:Id_def)
prensani@13020
    28
done
prensani@13020
    29
prensani@13020
    30
lemma BasicRule: "p \<subseteq> {s. (f s)\<in>q} \<Longrightarrow> \<parallel>- p (Basic f) q"
prensani@13020
    31
apply(rule oghoare_intros)
prensani@13020
    32
  prefer 2 apply(rule oghoare_intros)
prensani@13020
    33
 prefer 2 apply(rule subset_refl)
prensani@13020
    34
apply assumption
prensani@13020
    35
done
prensani@13020
    36
prensani@13020
    37
lemma SeqRule: "\<lbrakk> \<parallel>- p c1 r; \<parallel>- r c2 q \<rbrakk> \<Longrightarrow> \<parallel>- p (Seq c1 c2) q"
prensani@13020
    38
apply(rule Seq)
prensani@13020
    39
apply fast+
prensani@13020
    40
done
prensani@13020
    41
prensani@13020
    42
lemma CondRule: 
prensani@13020
    43
 "\<lbrakk> p \<subseteq> {s. (s\<in>b \<longrightarrow> s\<in>w) \<and> (s\<notin>b \<longrightarrow> s\<in>w')}; \<parallel>- w c1 q; \<parallel>- w' c2 q \<rbrakk> 
prensani@13020
    44
  \<Longrightarrow> \<parallel>- p (Cond b c1 c2) q"
prensani@13020
    45
apply(rule Cond)
prensani@13020
    46
 apply(rule Conseq)
prensani@13020
    47
 prefer 4 apply(rule Conseq)
prensani@13020
    48
apply simp_all
prensani@13020
    49
apply force+
prensani@13020
    50
done
prensani@13020
    51
prensani@13020
    52
lemma WhileRule: "\<lbrakk> p \<subseteq> i; \<parallel>- (i \<inter> b) c i ; (i \<inter> (-b)) \<subseteq> q \<rbrakk>  
prensani@13020
    53
        \<Longrightarrow> \<parallel>- p (While b i c) q"
prensani@13020
    54
apply(rule Conseq)
prensani@13020
    55
 prefer 2 apply(rule While)
prensani@13020
    56
apply assumption+
prensani@13020
    57
done
prensani@13020
    58
prensani@13020
    59
text {* Three new proof rules for special instances of the @{text
prensani@13020
    60
AnnBasic} and the @{text AnnAwait} commands when the transformation
prensani@13020
    61
performed on the state is the identity, and for an @{text AnnAwait}
prensani@13020
    62
command where the boolean condition is @{text "{s. True}"}: *}
prensani@13020
    63
prensani@13020
    64
lemma AnnatomRule:
prensani@13020
    65
  "\<lbrakk> atom_com(c); \<parallel>- r c q \<rbrakk>  \<Longrightarrow> \<turnstile> (AnnAwait r {s. True} c) q"
prensani@13020
    66
apply(rule AnnAwait)
prensani@13020
    67
apply simp_all
prensani@13020
    68
done
prensani@13020
    69
prensani@13020
    70
lemma AnnskipRule:
prensani@13020
    71
  "r \<subseteq> q \<Longrightarrow> \<turnstile> (AnnBasic r id) q"
prensani@13020
    72
apply(rule AnnBasic)
prensani@13020
    73
apply simp
prensani@13020
    74
done
prensani@13020
    75
prensani@13020
    76
lemma AnnwaitRule:
prensani@13020
    77
  "\<lbrakk> (r \<inter> b) \<subseteq> q \<rbrakk> \<Longrightarrow> \<turnstile> (AnnAwait r b (Basic id)) q"
prensani@13020
    78
apply(rule AnnAwait)
prensani@13020
    79
 apply simp
prensani@13020
    80
apply(rule BasicRule)
prensani@13020
    81
apply simp
prensani@13020
    82
done
prensani@13020
    83
prensani@13020
    84
text {* Lemmata to avoid using the definition of @{text
prensani@13020
    85
map_ann_hoare}, @{text interfree_aux}, @{text interfree_swap} and
prensani@13020
    86
@{text interfree} by splitting it into different cases: *}
prensani@13020
    87
prensani@13020
    88
lemma interfree_aux_rule1: "interfree_aux(co, q, None)"
prensani@13020
    89
by(simp add:interfree_aux_def)
prensani@13020
    90
prensani@13020
    91
lemma interfree_aux_rule2: 
prensani@13020
    92
  "\<forall>(R,r)\<in>(atomics a). \<parallel>- (q \<inter> R) r q \<Longrightarrow> interfree_aux(None, q, Some a)"
prensani@13020
    93
apply(simp add:interfree_aux_def)
prensani@13020
    94
apply(force elim:oghoare_sound)
prensani@13020
    95
done
prensani@13020
    96
prensani@13020
    97
lemma interfree_aux_rule3: 
prensani@13020
    98
  "(\<forall>(R, r)\<in>(atomics a). \<parallel>- (q \<inter> R) r q \<and> (\<forall>p\<in>(assertions c). \<parallel>- (p \<inter> R) r p))
prensani@13020
    99
  \<Longrightarrow> interfree_aux(Some c, q, Some a)"
prensani@13020
   100
apply(simp add:interfree_aux_def)
prensani@13020
   101
apply(force elim:oghoare_sound)
prensani@13020
   102
done
prensani@13020
   103
prensani@13020
   104
lemma AnnBasic_assertions: 
prensani@13020
   105
  "\<lbrakk>interfree_aux(None, r, Some a); interfree_aux(None, q, Some a)\<rbrakk> \<Longrightarrow> 
prensani@13020
   106
    interfree_aux(Some (AnnBasic r f), q, Some a)"
prensani@13020
   107
apply(simp add: interfree_aux_def)
prensani@13020
   108
by force
prensani@13020
   109
prensani@13020
   110
lemma AnnSeq_assertions: 
prensani@13020
   111
  "\<lbrakk> interfree_aux(Some c1, q, Some a); interfree_aux(Some c2, q, Some a)\<rbrakk>\<Longrightarrow> 
prensani@13020
   112
   interfree_aux(Some (AnnSeq c1 c2), q, Some a)"
prensani@13020
   113
apply(simp add: interfree_aux_def)
prensani@13020
   114
by force
prensani@13020
   115
prensani@13020
   116
lemma AnnCond1_assertions: 
prensani@13020
   117
  "\<lbrakk> interfree_aux(None, r, Some a); interfree_aux(Some c1, q, Some a); 
prensani@13020
   118
  interfree_aux(Some c2, q, Some a)\<rbrakk>\<Longrightarrow> 
prensani@13020
   119
  interfree_aux(Some(AnnCond1 r b c1 c2), q, Some a)"
prensani@13020
   120
apply(simp add: interfree_aux_def)
prensani@13020
   121
by force
prensani@13020
   122
prensani@13020
   123
lemma AnnCond2_assertions: 
prensani@13020
   124
  "\<lbrakk> interfree_aux(None, r, Some a); interfree_aux(Some c, q, Some a)\<rbrakk>\<Longrightarrow> 
prensani@13020
   125
  interfree_aux(Some (AnnCond2 r b c), q, Some a)"
prensani@13020
   126
apply(simp add: interfree_aux_def)
prensani@13020
   127
by force
prensani@13020
   128
prensani@13020
   129
lemma AnnWhile_assertions: 
prensani@13020
   130
  "\<lbrakk> interfree_aux(None, r, Some a); interfree_aux(None, i, Some a); 
prensani@13020
   131
  interfree_aux(Some c, q, Some a)\<rbrakk>\<Longrightarrow> 
prensani@13020
   132
  interfree_aux(Some (AnnWhile r b i c), q, Some a)"
prensani@13020
   133
apply(simp add: interfree_aux_def)
prensani@13020
   134
by force
prensani@13020
   135
 
prensani@13020
   136
lemma AnnAwait_assertions: 
prensani@13020
   137
  "\<lbrakk> interfree_aux(None, r, Some a); interfree_aux(None, q, Some a)\<rbrakk>\<Longrightarrow> 
prensani@13020
   138
  interfree_aux(Some (AnnAwait r b c), q, Some a)"
prensani@13020
   139
apply(simp add: interfree_aux_def)
prensani@13020
   140
by force
prensani@13020
   141
 
prensani@13020
   142
lemma AnnBasic_atomics: 
prensani@13020
   143
  "\<parallel>- (q \<inter> r) (Basic f) q \<Longrightarrow> interfree_aux(None, q, Some (AnnBasic r f))"
prensani@13020
   144
by(simp add: interfree_aux_def oghoare_sound)
prensani@13020
   145
prensani@13020
   146
lemma AnnSeq_atomics: 
prensani@13020
   147
  "\<lbrakk> interfree_aux(Any, q, Some a1); interfree_aux(Any, q, Some a2)\<rbrakk>\<Longrightarrow> 
prensani@13020
   148
  interfree_aux(Any, q, Some (AnnSeq a1 a2))"
prensani@13020
   149
apply(simp add: interfree_aux_def)
prensani@13020
   150
by force
prensani@13020
   151
prensani@13020
   152
lemma AnnCond1_atomics:
prensani@13020
   153
  "\<lbrakk> interfree_aux(Any, q, Some a1); interfree_aux(Any, q, Some a2)\<rbrakk>\<Longrightarrow> 
prensani@13020
   154
   interfree_aux(Any, q, Some (AnnCond1 r b a1 a2))"
prensani@13020
   155
apply(simp add: interfree_aux_def)
prensani@13020
   156
by force
prensani@13020
   157
prensani@13020
   158
lemma AnnCond2_atomics: 
prensani@13020
   159
  "interfree_aux (Any, q, Some a)\<Longrightarrow> interfree_aux(Any, q, Some (AnnCond2 r b a))"
prensani@13020
   160
by(simp add: interfree_aux_def)
prensani@13020
   161
prensani@13020
   162
lemma AnnWhile_atomics: "interfree_aux (Any, q, Some a) 
prensani@13020
   163
     \<Longrightarrow> interfree_aux(Any, q, Some (AnnWhile r b i a))"
prensani@13020
   164
by(simp add: interfree_aux_def)
prensani@13020
   165
prensani@13020
   166
lemma Annatom_atomics: 
prensani@13020
   167
  "\<parallel>- (q \<inter> r) a q \<Longrightarrow> interfree_aux (None, q, Some (AnnAwait r {x. True} a))"
prensani@13020
   168
by(simp add: interfree_aux_def oghoare_sound) 
prensani@13020
   169
prensani@13020
   170
lemma AnnAwait_atomics: 
prensani@13020
   171
  "\<parallel>- (q \<inter> (r \<inter> b)) a q \<Longrightarrow> interfree_aux (None, q, Some (AnnAwait r b a))"
prensani@13020
   172
by(simp add: interfree_aux_def oghoare_sound)
prensani@13020
   173
haftmann@35416
   174
definition interfree_swap :: "('a ann_triple_op * ('a ann_triple_op) list) \<Rightarrow> bool" where
prensani@13020
   175
  "interfree_swap == \<lambda>(x, xs). \<forall>y\<in>set xs. interfree_aux (com x, post x, com y)
prensani@13020
   176
  \<and> interfree_aux(com y, post y, com x)"
prensani@13020
   177
prensani@13020
   178
lemma interfree_swap_Empty: "interfree_swap (x, [])"
prensani@13020
   179
by(simp add:interfree_swap_def)
prensani@13020
   180
prensani@13020
   181
lemma interfree_swap_List:  
prensani@13020
   182
  "\<lbrakk> interfree_aux (com x, post x, com y); 
prensani@13020
   183
  interfree_aux (com y, post y ,com x); interfree_swap (x, xs) \<rbrakk> 
prensani@13020
   184
  \<Longrightarrow> interfree_swap (x, y#xs)"
prensani@13020
   185
by(simp add:interfree_swap_def)
prensani@13020
   186
prensani@13020
   187
lemma interfree_swap_Map: "\<forall>k. i\<le>k \<and> k<j \<longrightarrow> interfree_aux (com x, post x, c k) 
prensani@13020
   188
 \<and> interfree_aux (c k, Q k, com x)   
nipkow@15425
   189
 \<Longrightarrow> interfree_swap (x, map (\<lambda>k. (c k, Q k)) [i..<j])"
prensani@13020
   190
by(force simp add: interfree_swap_def less_diff_conv)
prensani@13020
   191
prensani@13020
   192
lemma interfree_Empty: "interfree []"
prensani@13020
   193
by(simp add:interfree_def)
prensani@13020
   194
prensani@13020
   195
lemma interfree_List: 
prensani@13020
   196
  "\<lbrakk> interfree_swap(x, xs); interfree xs \<rbrakk> \<Longrightarrow> interfree (x#xs)"
prensani@13020
   197
apply(simp add:interfree_def interfree_swap_def)
prensani@13020
   198
apply clarify
prensani@13020
   199
apply(case_tac i)
prensani@13020
   200
 apply(case_tac j)
prensani@13020
   201
  apply simp_all
prensani@13020
   202
apply(case_tac j,simp+)
prensani@13020
   203
done
prensani@13020
   204
prensani@13020
   205
lemma interfree_Map: 
prensani@13020
   206
  "(\<forall>i j. a\<le>i \<and> i<b \<and> a\<le>j \<and> j<b  \<and> i\<noteq>j \<longrightarrow> interfree_aux (c i, Q i, c j))  
nipkow@15425
   207
  \<Longrightarrow> interfree (map (\<lambda>k. (c k, Q k)) [a..<b])"
prensani@13020
   208
by(force simp add: interfree_def less_diff_conv)
prensani@13020
   209
haftmann@35416
   210
definition map_ann_hoare :: "(('a ann_com_op * 'a assn) list) \<Rightarrow> bool " ("[\<turnstile>] _" [0] 45) where
prensani@13020
   211
  "[\<turnstile>] Ts == (\<forall>i<length Ts. \<exists>c q. Ts!i=(Some c, q) \<and> \<turnstile> c q)"
prensani@13020
   212
prensani@13020
   213
lemma MapAnnEmpty: "[\<turnstile>] []"
prensani@13020
   214
by(simp add:map_ann_hoare_def)
prensani@13020
   215
prensani@13020
   216
lemma MapAnnList: "\<lbrakk> \<turnstile> c q ; [\<turnstile>] xs \<rbrakk> \<Longrightarrow> [\<turnstile>] (Some c,q)#xs"
prensani@13020
   217
apply(simp add:map_ann_hoare_def)
prensani@13020
   218
apply clarify
prensani@13020
   219
apply(case_tac i,simp+)
prensani@13020
   220
done
prensani@13020
   221
prensani@13020
   222
lemma MapAnnMap: 
nipkow@15425
   223
  "\<forall>k. i\<le>k \<and> k<j \<longrightarrow> \<turnstile> (c k) (Q k) \<Longrightarrow> [\<turnstile>] map (\<lambda>k. (Some (c k), Q k)) [i..<j]"
prensani@13020
   224
apply(simp add: map_ann_hoare_def less_diff_conv)
prensani@13020
   225
done
prensani@13020
   226
prensani@13020
   227
lemma ParallelRule:"\<lbrakk> [\<turnstile>] Ts ; interfree Ts \<rbrakk>
prensani@13020
   228
  \<Longrightarrow> \<parallel>- (\<Inter>i\<in>{i. i<length Ts}. pre(the(com(Ts!i)))) 
prensani@13020
   229
          Parallel Ts 
prensani@13020
   230
        (\<Inter>i\<in>{i. i<length Ts}. post(Ts!i))"
prensani@13020
   231
apply(rule Parallel)
prensani@13020
   232
 apply(simp add:map_ann_hoare_def)
prensani@13020
   233
apply simp
prensani@13020
   234
done
prensani@13020
   235
(*
prensani@13020
   236
lemma ParamParallelRule:
prensani@13020
   237
 "\<lbrakk> \<forall>k<n. \<turnstile> (c k) (Q k); 
prensani@13020
   238
   \<forall>k l. k<n \<and> l<n  \<and> k\<noteq>l \<longrightarrow> interfree_aux (Some(c k), Q k, Some(c l)) \<rbrakk>
prensani@13020
   239
  \<Longrightarrow> \<parallel>- (\<Inter>i\<in>{i. i<n} . pre(c i)) COBEGIN SCHEME [0\<le>i<n] (c i) (Q i) COEND  (\<Inter>i\<in>{i. i<n} . Q i )"
prensani@13020
   240
apply(rule ParallelConseqRule)
prensani@13020
   241
  apply simp
prensani@13020
   242
  apply clarify
prensani@13020
   243
  apply force
prensani@13020
   244
 apply(rule ParallelRule)
prensani@13020
   245
  apply(rule MapAnnMap)
prensani@13020
   246
  apply simp
prensani@13020
   247
 apply(rule interfree_Map)
prensani@13020
   248
 apply simp
prensani@13020
   249
apply simp
prensani@13020
   250
apply clarify
prensani@13020
   251
apply force
prensani@13020
   252
done
prensani@13020
   253
*)
prensani@13020
   254
prensani@13020
   255
text {* The following are some useful lemmas and simplification
prensani@13020
   256
tactics to control which theorems are used to simplify at each moment,
prensani@13020
   257
so that the original input does not suffer any unexpected
prensani@13020
   258
transformation. *}
prensani@13020
   259
prensani@13020
   260
lemma Compl_Collect: "-(Collect b) = {x. \<not>(b x)}"
prensani@13020
   261
by fast
prensani@13020
   262
lemma list_length: "length []=0 \<and> length (x#xs) = Suc(length xs)"
prensani@13020
   263
by simp
prensani@13020
   264
lemma list_lemmas: "length []=0 \<and> length (x#xs) = Suc(length xs) 
prensani@13020
   265
\<and> (x#xs) ! 0=x \<and> (x#xs) ! Suc n = xs ! n"
prensani@13020
   266
by simp
prensani@13020
   267
lemma le_Suc_eq_insert: "{i. i <Suc n} = insert n {i. i< n}"
nipkow@13187
   268
by auto
prensani@13020
   269
lemmas primrecdef_list = "pre.simps" "assertions.simps" "atomics.simps" "atom_com.simps"
prensani@13020
   270
lemmas my_simp_list = list_lemmas fst_conv snd_conv
haftmann@27104
   271
not_less0 refl le_Suc_eq_insert Suc_not_Zero Zero_not_Suc nat.inject
prensani@13020
   272
Collect_mem_eq ball_simps option.simps primrecdef_list
hoelzl@44928
   273
lemmas ParallelConseq_list = INTER_eq Collect_conj_eq length_map length_upt length_append list_length
prensani@13020
   274
prensani@13020
   275
ML {*
wenzelm@39159
   276
val before_interfree_simp_tac = simp_tac (HOL_basic_ss addsimps [@{thm com.simps}, @{thm post.simps}])
prensani@13020
   277
wenzelm@39159
   278
val  interfree_simp_tac = asm_simp_tac (HOL_ss addsimps [@{thm split}, @{thm ball_Un}, @{thm ball_empty}] @ @{thms my_simp_list})
prensani@13020
   279
wenzelm@39159
   280
val ParallelConseq = simp_tac (HOL_basic_ss addsimps @{thms ParallelConseq_list} @ @{thms my_simp_list})
prensani@13020
   281
*}
prensani@13020
   282
prensani@13020
   283
text {* The following tactic applies @{text tac} to each conjunct in a
prensani@13020
   284
subgoal of the form @{text "A \<Longrightarrow> a1 \<and> a2 \<and> .. \<and> an"}  returning
prensani@13020
   285
@{text n} subgoals, one for each conjunct: *}
prensani@13020
   286
prensani@13020
   287
ML {*
prensani@13020
   288
fun conjI_Tac tac i st = st |>
prensani@13020
   289
       ( (EVERY [rtac conjI i,
prensani@13020
   290
          conjI_Tac tac (i+1),
prensani@13020
   291
          tac i]) ORELSE (tac i) )
prensani@13020
   292
*}
prensani@13020
   293
prensani@13020
   294
prensani@13020
   295
subsubsection {* Tactic for the generation of the verification conditions *} 
prensani@13020
   296
prensani@13020
   297
text {* The tactic basically uses two subtactics:
prensani@13020
   298
prensani@13020
   299
\begin{description}
prensani@13020
   300
prensani@13020
   301
\item[HoareRuleTac] is called at the level of parallel programs, it        
prensani@13020
   302
 uses the ParallelTac to solve parallel composition of programs.         
prensani@13020
   303
 This verification has two parts, namely, (1) all component programs are 
prensani@13020
   304
 correct and (2) they are interference free.  @{text HoareRuleTac} is
prensani@13020
   305
 also called at the level of atomic regions, i.e.  @{text "\<langle> \<rangle>"} and
prensani@13020
   306
 @{text "AWAIT b THEN _ END"}, and at each interference freedom test.
prensani@13020
   307
prensani@13020
   308
\item[AnnHoareRuleTac] is for component programs which  
prensani@13020
   309
 are annotated programs and so, there are not unknown assertions         
prensani@13020
   310
 (no need to use the parameter precond, see NOTE).
prensani@13020
   311
prensani@13020
   312
 NOTE: precond(::bool) informs if the subgoal has the form @{text "\<parallel>- ?p c q"},
prensani@13020
   313
 in this case we have precond=False and the generated  verification     
prensani@13020
   314
 condition would have the form @{text "?p \<subseteq> \<dots>"} which can be solved by        
prensani@13020
   315
 @{text "rtac subset_refl"}, if True we proceed to simplify it using
prensani@13020
   316
 the simplification tactics above.
prensani@13020
   317
prensani@13020
   318
\end{description}
prensani@13020
   319
*}
prensani@13020
   320
prensani@13020
   321
ML {*
prensani@13020
   322
wenzelm@23894
   323
 fun WlpTac i = (rtac (@{thm SeqRule}) i) THEN (HoareRuleTac false (i+1))
prensani@13020
   324
and HoareRuleTac precond i st = st |>  
prensani@13020
   325
    ( (WlpTac i THEN HoareRuleTac precond i)
prensani@13020
   326
      ORELSE
wenzelm@23894
   327
      (FIRST[rtac (@{thm SkipRule}) i,
wenzelm@23894
   328
             rtac (@{thm BasicRule}) i,
wenzelm@23894
   329
             EVERY[rtac (@{thm ParallelConseqRule}) i,
prensani@13020
   330
                   ParallelConseq (i+2),
prensani@13020
   331
                   ParallelTac (i+1),
prensani@13020
   332
                   ParallelConseq i], 
wenzelm@23894
   333
             EVERY[rtac (@{thm CondRule}) i,
prensani@13020
   334
                   HoareRuleTac false (i+2),
prensani@13020
   335
                   HoareRuleTac false (i+1)],
wenzelm@23894
   336
             EVERY[rtac (@{thm WhileRule}) i,
prensani@13020
   337
                   HoareRuleTac true (i+1)],
prensani@13020
   338
             K all_tac i ]
wenzelm@23894
   339
       THEN (if precond then (K all_tac i) else (rtac (@{thm subset_refl}) i))))
prensani@13020
   340
wenzelm@23894
   341
and  AnnWlpTac i = (rtac (@{thm AnnSeq}) i) THEN (AnnHoareRuleTac (i+1))
prensani@13020
   342
and AnnHoareRuleTac i st = st |>  
prensani@13020
   343
    ( (AnnWlpTac i THEN AnnHoareRuleTac i )
prensani@13020
   344
     ORELSE
wenzelm@23894
   345
      (FIRST[(rtac (@{thm AnnskipRule}) i),
wenzelm@23894
   346
             EVERY[rtac (@{thm AnnatomRule}) i,
prensani@13020
   347
                   HoareRuleTac true (i+1)],
wenzelm@23894
   348
             (rtac (@{thm AnnwaitRule}) i),
wenzelm@23894
   349
             rtac (@{thm AnnBasic}) i,
wenzelm@23894
   350
             EVERY[rtac (@{thm AnnCond1}) i,
prensani@13020
   351
                   AnnHoareRuleTac (i+3),
prensani@13020
   352
                   AnnHoareRuleTac (i+1)],
wenzelm@23894
   353
             EVERY[rtac (@{thm AnnCond2}) i,
prensani@13020
   354
                   AnnHoareRuleTac (i+1)],
wenzelm@23894
   355
             EVERY[rtac (@{thm AnnWhile}) i,
prensani@13020
   356
                   AnnHoareRuleTac (i+2)],
wenzelm@23894
   357
             EVERY[rtac (@{thm AnnAwait}) i,
prensani@13020
   358
                   HoareRuleTac true (i+1)],
prensani@13020
   359
             K all_tac i]))
prensani@13020
   360
wenzelm@23894
   361
and ParallelTac i = EVERY[rtac (@{thm ParallelRule}) i,
prensani@13020
   362
                          interfree_Tac (i+1),
prensani@13020
   363
                           MapAnn_Tac i]
prensani@13020
   364
prensani@13020
   365
and MapAnn_Tac i st = st |>
wenzelm@23894
   366
    (FIRST[rtac (@{thm MapAnnEmpty}) i,
wenzelm@23894
   367
           EVERY[rtac (@{thm MapAnnList}) i,
prensani@13020
   368
                 MapAnn_Tac (i+1),
prensani@13020
   369
                 AnnHoareRuleTac i],
wenzelm@23894
   370
           EVERY[rtac (@{thm MapAnnMap}) i,
wenzelm@23894
   371
                 rtac (@{thm allI}) i,rtac (@{thm impI}) i,
prensani@13020
   372
                 AnnHoareRuleTac i]])
prensani@13020
   373
prensani@13020
   374
and interfree_swap_Tac i st = st |>
wenzelm@23894
   375
    (FIRST[rtac (@{thm interfree_swap_Empty}) i,
wenzelm@23894
   376
           EVERY[rtac (@{thm interfree_swap_List}) i,
prensani@13020
   377
                 interfree_swap_Tac (i+2),
prensani@13020
   378
                 interfree_aux_Tac (i+1),
prensani@13020
   379
                 interfree_aux_Tac i ],
wenzelm@23894
   380
           EVERY[rtac (@{thm interfree_swap_Map}) i,
wenzelm@23894
   381
                 rtac (@{thm allI}) i,rtac (@{thm impI}) i,
prensani@13020
   382
                 conjI_Tac (interfree_aux_Tac) i]])
prensani@13020
   383
prensani@13020
   384
and interfree_Tac i st = st |> 
wenzelm@23894
   385
   (FIRST[rtac (@{thm interfree_Empty}) i,
wenzelm@23894
   386
          EVERY[rtac (@{thm interfree_List}) i,
prensani@13020
   387
                interfree_Tac (i+1),
prensani@13020
   388
                interfree_swap_Tac i],
wenzelm@23894
   389
          EVERY[rtac (@{thm interfree_Map}) i,
wenzelm@23894
   390
                rtac (@{thm allI}) i,rtac (@{thm allI}) i,rtac (@{thm impI}) i,
prensani@13020
   391
                interfree_aux_Tac i ]])
prensani@13020
   392
prensani@13020
   393
and interfree_aux_Tac i = (before_interfree_simp_tac i ) THEN 
wenzelm@23894
   394
        (FIRST[rtac (@{thm interfree_aux_rule1}) i,
prensani@13020
   395
               dest_assertions_Tac i])
prensani@13020
   396
prensani@13020
   397
and dest_assertions_Tac i st = st |>
wenzelm@23894
   398
    (FIRST[EVERY[rtac (@{thm AnnBasic_assertions}) i,
prensani@13020
   399
                 dest_atomics_Tac (i+1),
prensani@13020
   400
                 dest_atomics_Tac i],
wenzelm@23894
   401
           EVERY[rtac (@{thm AnnSeq_assertions}) i,
prensani@13020
   402
                 dest_assertions_Tac (i+1),
prensani@13020
   403
                 dest_assertions_Tac i],
wenzelm@23894
   404
           EVERY[rtac (@{thm AnnCond1_assertions}) i,
prensani@13020
   405
                 dest_assertions_Tac (i+2),
prensani@13020
   406
                 dest_assertions_Tac (i+1),
prensani@13020
   407
                 dest_atomics_Tac i],
wenzelm@23894
   408
           EVERY[rtac (@{thm AnnCond2_assertions}) i,
prensani@13020
   409
                 dest_assertions_Tac (i+1),
prensani@13020
   410
                 dest_atomics_Tac i],
wenzelm@23894
   411
           EVERY[rtac (@{thm AnnWhile_assertions}) i,
prensani@13020
   412
                 dest_assertions_Tac (i+2),
prensani@13020
   413
                 dest_atomics_Tac (i+1),
prensani@13020
   414
                 dest_atomics_Tac i],
wenzelm@23894
   415
           EVERY[rtac (@{thm AnnAwait_assertions}) i,
prensani@13020
   416
                 dest_atomics_Tac (i+1),
prensani@13020
   417
                 dest_atomics_Tac i],
prensani@13020
   418
           dest_atomics_Tac i])
prensani@13020
   419
prensani@13020
   420
and dest_atomics_Tac i st = st |>
wenzelm@23894
   421
    (FIRST[EVERY[rtac (@{thm AnnBasic_atomics}) i,
prensani@13020
   422
                 HoareRuleTac true i],
wenzelm@23894
   423
           EVERY[rtac (@{thm AnnSeq_atomics}) i,
prensani@13020
   424
                 dest_atomics_Tac (i+1),
prensani@13020
   425
                 dest_atomics_Tac i],
wenzelm@23894
   426
           EVERY[rtac (@{thm AnnCond1_atomics}) i,
prensani@13020
   427
                 dest_atomics_Tac (i+1),
prensani@13020
   428
                 dest_atomics_Tac i],
wenzelm@23894
   429
           EVERY[rtac (@{thm AnnCond2_atomics}) i,
prensani@13020
   430
                 dest_atomics_Tac i],
wenzelm@23894
   431
           EVERY[rtac (@{thm AnnWhile_atomics}) i,
prensani@13020
   432
                 dest_atomics_Tac i],
wenzelm@23894
   433
           EVERY[rtac (@{thm Annatom_atomics}) i,
prensani@13020
   434
                 HoareRuleTac true i],
wenzelm@23894
   435
           EVERY[rtac (@{thm AnnAwait_atomics}) i,
prensani@13020
   436
                 HoareRuleTac true i],
prensani@13020
   437
                 K all_tac i])
prensani@13020
   438
*}
prensani@13020
   439
prensani@13020
   440
prensani@13020
   441
text {* The final tactic is given the name @{text oghoare}: *}
prensani@13020
   442
prensani@13020
   443
ML {* 
wenzelm@23894
   444
val oghoare_tac = SUBGOAL (fn (_, i) =>
wenzelm@23894
   445
   (HoareRuleTac true i))
prensani@13020
   446
*}
prensani@13020
   447
prensani@13020
   448
text {* Notice that the tactic for parallel programs @{text
prensani@13020
   449
"oghoare_tac"} is initially invoked with the value @{text true} for
prensani@13020
   450
the parameter @{text precond}.
prensani@13020
   451
prensani@13020
   452
Parts of the tactic can be also individually used to generate the
prensani@13020
   453
verification conditions for annotated sequential programs and to
prensani@13020
   454
generate verification conditions out of interference freedom tests: *}
prensani@13020
   455
wenzelm@23894
   456
ML {* val annhoare_tac = SUBGOAL (fn (_, i) =>
wenzelm@23894
   457
  (AnnHoareRuleTac i))
prensani@13020
   458
wenzelm@23894
   459
val interfree_aux_tac = SUBGOAL (fn (_, i) =>
wenzelm@23894
   460
   (interfree_aux_Tac i))
prensani@13020
   461
*}
prensani@13020
   462
prensani@13020
   463
text {* The so defined ML tactics are then ``exported'' to be used in
prensani@13020
   464
Isabelle proofs. *}
prensani@13020
   465
prensani@13020
   466
method_setup oghoare = {*
wenzelm@30549
   467
  Scan.succeed (K (SIMPLE_METHOD' oghoare_tac)) *}
prensani@13020
   468
  "verification condition generator for the oghoare logic"
prensani@13020
   469
prensani@13020
   470
method_setup annhoare = {*
wenzelm@30549
   471
  Scan.succeed (K (SIMPLE_METHOD' annhoare_tac)) *}
prensani@13020
   472
  "verification condition generator for the ann_hoare logic"
prensani@13020
   473
prensani@13020
   474
method_setup interfree_aux = {*
wenzelm@30549
   475
  Scan.succeed (K (SIMPLE_METHOD' interfree_aux_tac)) *}
prensani@13020
   476
  "verification condition generator for interference freedom tests"
prensani@13020
   477
prensani@13020
   478
text {* Tactics useful for dealing with the generated verification conditions: *}
prensani@13020
   479
prensani@13020
   480
method_setup conjI_tac = {*
wenzelm@30549
   481
  Scan.succeed (K (SIMPLE_METHOD' (conjI_Tac (K all_tac)))) *}
prensani@13020
   482
  "verification condition generator for interference freedom tests"
prensani@13020
   483
prensani@13020
   484
ML {*
prensani@13020
   485
fun disjE_Tac tac i st = st |>
prensani@13020
   486
       ( (EVERY [etac disjE i,
prensani@13020
   487
          disjE_Tac tac (i+1),
prensani@13020
   488
          tac i]) ORELSE (tac i) )
prensani@13020
   489
*}
prensani@13020
   490
prensani@13020
   491
method_setup disjE_tac = {*
wenzelm@30549
   492
  Scan.succeed (K (SIMPLE_METHOD' (disjE_Tac (K all_tac)))) *}
prensani@13020
   493
  "verification condition generator for interference freedom tests"
prensani@13020
   494
nipkow@13187
   495
end