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