author | wenzelm |
Thu, 02 Dec 2010 17:20:34 +0100 | |
changeset 40880 | be44a567ed28 |
parent 37671 | fa53d267dab3 |
child 41818 | 6d4c3ee8219d |
permissions | -rw-r--r-- |
33026 | 1 |
(* Title: HOL/Isar_Examples/Hoare.thy |
10148 | 2 |
Author: Markus Wenzel, TU Muenchen |
3 |
||
4 |
A formulation of Hoare logic suitable for Isar. |
|
5 |
*) |
|
6 |
||
7 |
header {* Hoare Logic *} |
|
8 |
||
31758 | 9 |
theory Hoare |
10 |
imports Main |
|
11 |
uses ("~~/src/HOL/Hoare/hoare_tac.ML") |
|
12 |
begin |
|
10148 | 13 |
|
14 |
subsection {* Abstract syntax and semantics *} |
|
15 |
||
37671 | 16 |
text {* The following abstract syntax and semantics of Hoare Logic |
17 |
over \texttt{WHILE} programs closely follows the existing tradition |
|
18 |
in Isabelle/HOL of formalizing the presentation given in |
|
40880 | 19 |
\cite[\S6]{Winskel:1993}. See also @{file "~~/src/HOL/Hoare"} and |
37671 | 20 |
\cite{Nipkow:1998:Winskel}. *} |
10148 | 21 |
|
22 |
types |
|
23 |
'a bexp = "'a set" |
|
24 |
'a assn = "'a set" |
|
25 |
||
26 |
datatype 'a com = |
|
27 |
Basic "'a => 'a" |
|
28 |
| Seq "'a com" "'a com" ("(_;/ _)" [60, 61] 60) |
|
29 |
| Cond "'a bexp" "'a com" "'a com" |
|
30 |
| While "'a bexp" "'a assn" "'a com" |
|
31 |
||
37671 | 32 |
abbreviation Skip ("SKIP") |
33 |
where "SKIP == Basic id" |
|
10148 | 34 |
|
35 |
types |
|
36 |
'a sem = "'a => 'a => bool" |
|
37 |
||
37671 | 38 |
primrec iter :: "nat => 'a bexp => 'a sem => 'a sem" |
39 |
where |
|
10148 | 40 |
"iter 0 b S s s' = (s ~: b & s = s')" |
37671 | 41 |
| "iter (Suc n) b S s s' = (s : b & (EX s''. S s s'' & iter n b S s'' s'))" |
10148 | 42 |
|
37671 | 43 |
primrec Sem :: "'a com => 'a sem" |
44 |
where |
|
10148 | 45 |
"Sem (Basic f) s s' = (s' = f s)" |
37671 | 46 |
| "Sem (c1; c2) s s' = (EX s''. Sem c1 s s'' & Sem c2 s'' s')" |
47 |
| "Sem (Cond b c1 c2) s s' = |
|
10148 | 48 |
(if s : b then Sem c1 s s' else Sem c2 s s')" |
37671 | 49 |
| "Sem (While b x c) s s' = (EX n. iter n b (Sem c) s s')" |
10148 | 50 |
|
37671 | 51 |
definition |
52 |
Valid :: "'a bexp => 'a com => 'a bexp => bool" |
|
53 |
("(3|- _/ (2_)/ _)" [100, 55, 100] 50) |
|
54 |
where "|- P c Q \<longleftrightarrow> (\<forall>s s'. Sem c s s' --> s : P --> s' : Q)" |
|
10148 | 55 |
|
37671 | 56 |
notation (xsymbols) Valid ("(3\<turnstile> _/ (2_)/ _)" [100, 55, 100] 50) |
10148 | 57 |
|
58 |
lemma ValidI [intro?]: |
|
59 |
"(!!s s'. Sem c s s' ==> s : P ==> s' : Q) ==> |- P c Q" |
|
60 |
by (simp add: Valid_def) |
|
61 |
||
62 |
lemma ValidD [dest?]: |
|
63 |
"|- P c Q ==> Sem c s s' ==> s : P ==> s' : Q" |
|
64 |
by (simp add: Valid_def) |
|
65 |
||
66 |
||
67 |
subsection {* Primitive Hoare rules *} |
|
68 |
||
37671 | 69 |
text {* From the semantics defined above, we derive the standard set |
70 |
of primitive Hoare rules; e.g.\ see \cite[\S6]{Winskel:1993}. |
|
71 |
Usually, variant forms of these rules are applied in actual proof, |
|
72 |
see also \S\ref{sec:hoare-isar} and \S\ref{sec:hoare-vcg}. |
|
10148 | 73 |
|
37671 | 74 |
\medskip The \name{basic} rule represents any kind of atomic access |
75 |
to the state space. This subsumes the common rules of \name{skip} |
|
76 |
and \name{assign}, as formulated in \S\ref{sec:hoare-isar}. *} |
|
10148 | 77 |
|
78 |
theorem basic: "|- {s. f s : P} (Basic f) P" |
|
79 |
proof |
|
80 |
fix s s' assume s: "s : {s. f s : P}" |
|
81 |
assume "Sem (Basic f) s s'" |
|
37671 | 82 |
then have "s' = f s" by simp |
10148 | 83 |
with s show "s' : P" by simp |
84 |
qed |
|
85 |
||
86 |
text {* |
|
87 |
The rules for sequential commands and semantic consequences are |
|
88 |
established in a straight forward manner as follows. |
|
89 |
*} |
|
90 |
||
91 |
theorem seq: "|- P c1 Q ==> |- Q c2 R ==> |- P (c1; c2) R" |
|
92 |
proof |
|
93 |
assume cmd1: "|- P c1 Q" and cmd2: "|- Q c2 R" |
|
94 |
fix s s' assume s: "s : P" |
|
95 |
assume "Sem (c1; c2) s s'" |
|
96 |
then obtain s'' where sem1: "Sem c1 s s''" and sem2: "Sem c2 s'' s'" |
|
97 |
by auto |
|
98 |
from cmd1 sem1 s have "s'' : Q" .. |
|
99 |
with cmd2 sem2 show "s' : R" .. |
|
100 |
qed |
|
101 |
||
102 |
theorem conseq: "P' <= P ==> |- P c Q ==> Q <= Q' ==> |- P' c Q'" |
|
103 |
proof |
|
104 |
assume P'P: "P' <= P" and QQ': "Q <= Q'" |
|
105 |
assume cmd: "|- P c Q" |
|
106 |
fix s s' :: 'a |
|
107 |
assume sem: "Sem c s s'" |
|
108 |
assume "s : P'" with P'P have "s : P" .. |
|
109 |
with cmd sem have "s' : Q" .. |
|
110 |
with QQ' show "s' : Q'" .. |
|
111 |
qed |
|
112 |
||
37671 | 113 |
text {* The rule for conditional commands is directly reflected by the |
114 |
corresponding semantics; in the proof we just have to look closely |
|
115 |
which cases apply. *} |
|
10148 | 116 |
|
117 |
theorem cond: |
|
118 |
"|- (P Int b) c1 Q ==> |- (P Int -b) c2 Q ==> |- P (Cond b c1 c2) Q" |
|
119 |
proof |
|
120 |
assume case_b: "|- (P Int b) c1 Q" and case_nb: "|- (P Int -b) c2 Q" |
|
121 |
fix s s' assume s: "s : P" |
|
122 |
assume sem: "Sem (Cond b c1 c2) s s'" |
|
123 |
show "s' : Q" |
|
124 |
proof cases |
|
125 |
assume b: "s : b" |
|
126 |
from case_b show ?thesis |
|
127 |
proof |
|
128 |
from sem b show "Sem c1 s s'" by simp |
|
129 |
from s b show "s : P Int b" by simp |
|
130 |
qed |
|
131 |
next |
|
132 |
assume nb: "s ~: b" |
|
133 |
from case_nb show ?thesis |
|
134 |
proof |
|
135 |
from sem nb show "Sem c2 s s'" by simp |
|
136 |
from s nb show "s : P Int -b" by simp |
|
137 |
qed |
|
138 |
qed |
|
139 |
qed |
|
140 |
||
37671 | 141 |
text {* The @{text while} rule is slightly less trivial --- it is the |
142 |
only one based on recursion, which is expressed in the semantics by |
|
143 |
a Kleene-style least fixed-point construction. The auxiliary |
|
144 |
statement below, which is by induction on the number of iterations |
|
145 |
is the main point to be proven; the rest is by routine application |
|
146 |
of the semantics of \texttt{WHILE}. *} |
|
10148 | 147 |
|
18241 | 148 |
theorem while: |
149 |
assumes body: "|- (P Int b) c P" |
|
150 |
shows "|- P (While b X c) (P Int -b)" |
|
10148 | 151 |
proof |
152 |
fix s s' assume s: "s : P" |
|
153 |
assume "Sem (While b X c) s s'" |
|
18241 | 154 |
then obtain n where "iter n b (Sem c) s s'" by auto |
155 |
from this and s show "s' : P Int -b" |
|
20503 | 156 |
proof (induct n arbitrary: s) |
19122 | 157 |
case 0 |
37671 | 158 |
then show ?case by auto |
11987 | 159 |
next |
19122 | 160 |
case (Suc n) |
11987 | 161 |
then obtain s'' where b: "s : b" and sem: "Sem c s s''" |
37671 | 162 |
and iter: "iter n b (Sem c) s'' s'" by auto |
11987 | 163 |
from Suc and b have "s : P Int b" by simp |
164 |
with body sem have "s'' : P" .. |
|
165 |
with iter show ?case by (rule Suc) |
|
10148 | 166 |
qed |
167 |
qed |
|
168 |
||
169 |
||
170 |
subsection {* Concrete syntax for assertions *} |
|
171 |
||
37671 | 172 |
text {* We now introduce concrete syntax for describing commands (with |
173 |
embedded expressions) and assertions. The basic technique is that of |
|
174 |
semantic ``quote-antiquote''. A \emph{quotation} is a syntactic |
|
175 |
entity delimited by an implicit abstraction, say over the state |
|
176 |
space. An \emph{antiquotation} is a marked expression within a |
|
177 |
quotation that refers the implicit argument; a typical antiquotation |
|
178 |
would select (or even update) components from the state. |
|
10148 | 179 |
|
37671 | 180 |
We will see some examples later in the concrete rules and |
181 |
applications. *} |
|
10148 | 182 |
|
37671 | 183 |
text {* The following specification of syntax and translations is for |
184 |
Isabelle experts only; feel free to ignore it. |
|
10148 | 185 |
|
37671 | 186 |
While the first part is still a somewhat intelligible specification |
187 |
of the concrete syntactic representation of our Hoare language, the |
|
188 |
actual ``ML drivers'' is quite involved. Just note that the we |
|
189 |
re-use the basic quote/antiquote translations as already defined in |
|
190 |
Isabelle/Pure (see \verb,Syntax.quote_tr, and |
|
191 |
\verb,Syntax.quote_tr',). *} |
|
10148 | 192 |
|
193 |
syntax |
|
10874 | 194 |
"_quote" :: "'b => ('a => 'b)" ("(.'(_').)" [0] 1000) |
195 |
"_antiquote" :: "('a => 'b) => 'b" ("\<acute>_" [1000] 1000) |
|
196 |
"_Subst" :: "'a bexp \<Rightarrow> 'b \<Rightarrow> idt \<Rightarrow> 'a bexp" |
|
197 |
("_[_'/\<acute>_]" [1000] 999) |
|
198 |
"_Assert" :: "'a => 'a set" ("(.{_}.)" [0] 1000) |
|
199 |
"_Assign" :: "idt => 'b => 'a com" ("(\<acute>_ :=/ _)" [70, 65] 61) |
|
10148 | 200 |
"_Cond" :: "'a bexp => 'a com => 'a com => 'a com" |
201 |
("(0IF _/ THEN _/ ELSE _/ FI)" [0, 0, 0] 61) |
|
202 |
"_While_inv" :: "'a bexp => 'a assn => 'a com => 'a com" |
|
203 |
("(0WHILE _/ INV _ //DO _ /OD)" [0, 0, 0] 61) |
|
204 |
"_While" :: "'a bexp => 'a com => 'a com" |
|
205 |
("(0WHILE _ //DO _ /OD)" [0, 0] 61) |
|
206 |
||
207 |
syntax (xsymbols) |
|
208 |
"_Assert" :: "'a => 'a set" ("(\<lbrace>_\<rbrace>)" [0] 1000) |
|
209 |
||
210 |
translations |
|
35054 | 211 |
".{b}." => "CONST Collect .(b)." |
25706 | 212 |
"B [a/\<acute>x]" => ".{\<acute>(_update_name x (\<lambda>_. a)) \<in> B}." |
35054 | 213 |
"\<acute>x := a" => "CONST Basic .(\<acute>(_update_name x (\<lambda>_. a)))." |
214 |
"IF b THEN c1 ELSE c2 FI" => "CONST Cond .{b}. c1 c2" |
|
215 |
"WHILE b INV i DO c OD" => "CONST While .{b}. i c" |
|
28524 | 216 |
"WHILE b DO c OD" == "WHILE b INV CONST undefined DO c OD" |
10148 | 217 |
|
218 |
parse_translation {* |
|
219 |
let |
|
35113 | 220 |
fun quote_tr [t] = Syntax.quote_tr @{syntax_const "_antiquote"} t |
10148 | 221 |
| quote_tr ts = raise TERM ("quote_tr", ts); |
35113 | 222 |
in [(@{syntax_const "_quote"}, quote_tr)] end |
10148 | 223 |
*} |
224 |
||
37671 | 225 |
text {* As usual in Isabelle syntax translations, the part for |
226 |
printing is more complicated --- we cannot express parts as macro |
|
227 |
rules as above. Don't look here, unless you have to do similar |
|
228 |
things for yourself. *} |
|
10148 | 229 |
|
230 |
print_translation {* |
|
231 |
let |
|
232 |
fun quote_tr' f (t :: ts) = |
|
35113 | 233 |
Term.list_comb (f $ Syntax.quote_tr' @{syntax_const "_antiquote"} t, ts) |
10148 | 234 |
| quote_tr' _ _ = raise Match; |
235 |
||
35113 | 236 |
val assert_tr' = quote_tr' (Syntax.const @{syntax_const "_Assert"}); |
10148 | 237 |
|
35113 | 238 |
fun bexp_tr' name ((Const (@{const_syntax Collect}, _) $ t) :: ts) = |
10148 | 239 |
quote_tr' (Syntax.const name) (t :: ts) |
240 |
| bexp_tr' _ _ = raise Match; |
|
241 |
||
35145
f132a4fd8679
moved generic update_name to Pure syntax -- not specific to HOL/record;
wenzelm
parents:
35113
diff
changeset
|
242 |
fun K_tr' (Abs (_, _, t)) = |
f132a4fd8679
moved generic update_name to Pure syntax -- not specific to HOL/record;
wenzelm
parents:
35113
diff
changeset
|
243 |
if null (loose_bnos t) then t else raise Match |
f132a4fd8679
moved generic update_name to Pure syntax -- not specific to HOL/record;
wenzelm
parents:
35113
diff
changeset
|
244 |
| K_tr' (Abs (_, _, Abs (_, _, t) $ Bound 0)) = |
f132a4fd8679
moved generic update_name to Pure syntax -- not specific to HOL/record;
wenzelm
parents:
35113
diff
changeset
|
245 |
if null (loose_bnos t) then t else raise Match |
25706 | 246 |
| K_tr' _ = raise Match; |
247 |
||
248 |
fun assign_tr' (Abs (x, _, f $ k $ Bound 0) :: ts) = |
|
35145
f132a4fd8679
moved generic update_name to Pure syntax -- not specific to HOL/record;
wenzelm
parents:
35113
diff
changeset
|
249 |
quote_tr' (Syntax.const @{syntax_const "_Assign"} $ Syntax.update_name_tr' f) |
25706 | 250 |
(Abs (x, dummyT, K_tr' k) :: ts) |
10148 | 251 |
| assign_tr' _ = raise Match; |
252 |
in |
|
35113 | 253 |
[(@{const_syntax Collect}, assert_tr'), |
254 |
(@{const_syntax Basic}, assign_tr'), |
|
255 |
(@{const_syntax Cond}, bexp_tr' @{syntax_const "_Cond"}), |
|
256 |
(@{const_syntax While}, bexp_tr' @{syntax_const "_While_inv"})] |
|
10148 | 257 |
end |
258 |
*} |
|
259 |
||
260 |
||
261 |
subsection {* Rules for single-step proof \label{sec:hoare-isar} *} |
|
262 |
||
37671 | 263 |
text {* We are now ready to introduce a set of Hoare rules to be used |
264 |
in single-step structured proofs in Isabelle/Isar. We refer to the |
|
265 |
concrete syntax introduce above. |
|
10148 | 266 |
|
37671 | 267 |
\medskip Assertions of Hoare Logic may be manipulated in |
268 |
calculational proofs, with the inclusion expressed in terms of sets |
|
269 |
or predicates. Reversed order is supported as well. *} |
|
10148 | 270 |
|
271 |
lemma [trans]: "|- P c Q ==> P' <= P ==> |- P' c Q" |
|
272 |
by (unfold Valid_def) blast |
|
273 |
lemma [trans] : "P' <= P ==> |- P c Q ==> |- P' c Q" |
|
274 |
by (unfold Valid_def) blast |
|
275 |
||
276 |
lemma [trans]: "Q <= Q' ==> |- P c Q ==> |- P c Q'" |
|
277 |
by (unfold Valid_def) blast |
|
278 |
lemma [trans]: "|- P c Q ==> Q <= Q' ==> |- P c Q'" |
|
279 |
by (unfold Valid_def) blast |
|
280 |
||
281 |
lemma [trans]: |
|
10838 | 282 |
"|- .{\<acute>P}. c Q ==> (!!s. P' s --> P s) ==> |- .{\<acute>P'}. c Q" |
10148 | 283 |
by (simp add: Valid_def) |
284 |
lemma [trans]: |
|
10838 | 285 |
"(!!s. P' s --> P s) ==> |- .{\<acute>P}. c Q ==> |- .{\<acute>P'}. c Q" |
10148 | 286 |
by (simp add: Valid_def) |
287 |
||
288 |
lemma [trans]: |
|
10838 | 289 |
"|- P c .{\<acute>Q}. ==> (!!s. Q s --> Q' s) ==> |- P c .{\<acute>Q'}." |
10148 | 290 |
by (simp add: Valid_def) |
291 |
lemma [trans]: |
|
10838 | 292 |
"(!!s. Q s --> Q' s) ==> |- P c .{\<acute>Q}. ==> |- P c .{\<acute>Q'}." |
10148 | 293 |
by (simp add: Valid_def) |
294 |
||
295 |
||
37671 | 296 |
text {* Identity and basic assignments.\footnote{The $\idt{hoare}$ |
297 |
method introduced in \S\ref{sec:hoare-vcg} is able to provide proper |
|
298 |
instances for any number of basic assignments, without producing |
|
299 |
additional verification conditions.} *} |
|
10148 | 300 |
|
301 |
lemma skip [intro?]: "|- P SKIP P" |
|
302 |
proof - |
|
303 |
have "|- {s. id s : P} SKIP P" by (rule basic) |
|
37671 | 304 |
then show ?thesis by simp |
10148 | 305 |
qed |
306 |
||
10869 | 307 |
lemma assign: "|- P [\<acute>a/\<acute>x] \<acute>x := \<acute>a P" |
10148 | 308 |
by (rule basic) |
309 |
||
37671 | 310 |
text {* Note that above formulation of assignment corresponds to our |
311 |
preferred way to model state spaces, using (extensible) record types |
|
312 |
in HOL \cite{Naraschewski-Wenzel:1998:HOOL}. For any record field |
|
313 |
$x$, Isabelle/HOL provides a functions $x$ (selector) and |
|
314 |
$\idt{x{\dsh}update}$ (update). Above, there is only a place-holder |
|
315 |
appearing for the latter kind of function: due to concrete syntax |
|
316 |
\isa{\'x := \'a} also contains \isa{x\_update}.\footnote{Note that |
|
317 |
due to the external nature of HOL record fields, we could not even |
|
318 |
state a general theorem relating selector and update functions (if |
|
319 |
this were required here); this would only work for any particular |
|
320 |
instance of record fields introduced so far.} *} |
|
10148 | 321 |
|
37671 | 322 |
text {* Sequential composition --- normalizing with associativity |
323 |
achieves proper of chunks of code verified separately. *} |
|
10148 | 324 |
|
325 |
lemmas [trans, intro?] = seq |
|
326 |
||
327 |
lemma seq_assoc [simp]: "( |- P c1;(c2;c3) Q) = ( |- P (c1;c2);c3 Q)" |
|
328 |
by (auto simp add: Valid_def) |
|
329 |
||
37671 | 330 |
text {* Conditional statements. *} |
10148 | 331 |
|
332 |
lemmas [trans, intro?] = cond |
|
333 |
||
334 |
lemma [trans, intro?]: |
|
10838 | 335 |
"|- .{\<acute>P & \<acute>b}. c1 Q |
336 |
==> |- .{\<acute>P & ~ \<acute>b}. c2 Q |
|
337 |
==> |- .{\<acute>P}. IF \<acute>b THEN c1 ELSE c2 FI Q" |
|
10148 | 338 |
by (rule cond) (simp_all add: Valid_def) |
339 |
||
37671 | 340 |
text {* While statements --- with optional invariant. *} |
10148 | 341 |
|
342 |
lemma [intro?]: |
|
343 |
"|- (P Int b) c P ==> |- P (While b P c) (P Int -b)" |
|
344 |
by (rule while) |
|
345 |
||
346 |
lemma [intro?]: |
|
28524 | 347 |
"|- (P Int b) c P ==> |- P (While b undefined c) (P Int -b)" |
10148 | 348 |
by (rule while) |
349 |
||
350 |
||
351 |
lemma [intro?]: |
|
10838 | 352 |
"|- .{\<acute>P & \<acute>b}. c .{\<acute>P}. |
353 |
==> |- .{\<acute>P}. WHILE \<acute>b INV .{\<acute>P}. DO c OD .{\<acute>P & ~ \<acute>b}." |
|
10148 | 354 |
by (simp add: while Collect_conj_eq Collect_neg_eq) |
355 |
||
356 |
lemma [intro?]: |
|
10838 | 357 |
"|- .{\<acute>P & \<acute>b}. c .{\<acute>P}. |
358 |
==> |- .{\<acute>P}. WHILE \<acute>b DO c OD .{\<acute>P & ~ \<acute>b}." |
|
10148 | 359 |
by (simp add: while Collect_conj_eq Collect_neg_eq) |
360 |
||
361 |
||
362 |
subsection {* Verification conditions \label{sec:hoare-vcg} *} |
|
363 |
||
37671 | 364 |
text {* We now load the \emph{original} ML file for proof scripts and |
365 |
tactic definition for the Hoare Verification Condition Generator |
|
40880 | 366 |
(see @{file "~~/src/HOL/Hoare/"}). As far as we |
37671 | 367 |
are concerned here, the result is a proof method \name{hoare}, which |
368 |
may be applied to a Hoare Logic assertion to extract purely logical |
|
369 |
verification conditions. It is important to note that the method |
|
370 |
requires \texttt{WHILE} loops to be fully annotated with invariants |
|
371 |
beforehand. Furthermore, only \emph{concrete} pieces of code are |
|
372 |
handled --- the underlying tactic fails ungracefully if supplied |
|
373 |
with meta-variables or parameters, for example. *} |
|
10148 | 374 |
|
13862 | 375 |
lemma SkipRule: "p \<subseteq> q \<Longrightarrow> Valid p (Basic id) q" |
18193 | 376 |
by (auto simp add: Valid_def) |
13862 | 377 |
|
378 |
lemma BasicRule: "p \<subseteq> {s. f s \<in> q} \<Longrightarrow> Valid p (Basic f) q" |
|
18193 | 379 |
by (auto simp: Valid_def) |
13862 | 380 |
|
381 |
lemma SeqRule: "Valid P c1 Q \<Longrightarrow> Valid Q c2 R \<Longrightarrow> Valid P (c1;c2) R" |
|
18193 | 382 |
by (auto simp: Valid_def) |
13862 | 383 |
|
384 |
lemma CondRule: |
|
18193 | 385 |
"p \<subseteq> {s. (s \<in> b \<longrightarrow> s \<in> w) \<and> (s \<notin> b \<longrightarrow> s \<in> w')} |
386 |
\<Longrightarrow> Valid w c1 q \<Longrightarrow> Valid w' c2 q \<Longrightarrow> Valid p (Cond b c1 c2) q" |
|
387 |
by (auto simp: Valid_def) |
|
13862 | 388 |
|
18241 | 389 |
lemma iter_aux: |
390 |
"\<forall>s s'. Sem c s s' --> s : I & s : b --> s' : I ==> |
|
18193 | 391 |
(\<And>s s'. s : I \<Longrightarrow> iter n b (Sem c) s s' \<Longrightarrow> s' : I & s' ~: b)" |
392 |
apply(induct n) |
|
393 |
apply clarsimp |
|
394 |
apply (simp (no_asm_use)) |
|
395 |
apply blast |
|
396 |
done |
|
13862 | 397 |
|
398 |
lemma WhileRule: |
|
18193 | 399 |
"p \<subseteq> i \<Longrightarrow> Valid (i \<inter> b) c i \<Longrightarrow> i \<inter> (-b) \<subseteq> q \<Longrightarrow> Valid p (While b i c) q" |
400 |
apply (clarsimp simp: Valid_def) |
|
401 |
apply (drule iter_aux) |
|
402 |
prefer 2 |
|
403 |
apply assumption |
|
404 |
apply blast |
|
405 |
apply blast |
|
406 |
done |
|
13862 | 407 |
|
26303 | 408 |
lemma Compl_Collect: "- Collect b = {x. \<not> b x}" |
409 |
by blast |
|
410 |
||
28457
25669513fd4c
major cleanup of hoare_tac.ML: just one copy for Hoare.thy and HoareAbort.thy (only 1 line different), refrain from inspecting the main goal, proper context;
wenzelm
parents:
26303
diff
changeset
|
411 |
lemmas AbortRule = SkipRule -- "dummy version" |
25669513fd4c
major cleanup of hoare_tac.ML: just one copy for Hoare.thy and HoareAbort.thy (only 1 line different), refrain from inspecting the main goal, proper context;
wenzelm
parents:
26303
diff
changeset
|
412 |
|
24472
943ef707396c
added Hoare/hoare_tac.ML (code from Hoare/Hoare.thy, also required in Isar_examples/Hoare.thy);
wenzelm
parents:
22759
diff
changeset
|
413 |
use "~~/src/HOL/Hoare/hoare_tac.ML" |
10148 | 414 |
|
415 |
method_setup hoare = {* |
|
30549 | 416 |
Scan.succeed (fn ctxt => |
30510
4120fc59dd85
unified type Proof.method and pervasive METHOD combinators;
wenzelm
parents:
28524
diff
changeset
|
417 |
(SIMPLE_METHOD' |
28457
25669513fd4c
major cleanup of hoare_tac.ML: just one copy for Hoare.thy and HoareAbort.thy (only 1 line different), refrain from inspecting the main goal, proper context;
wenzelm
parents:
26303
diff
changeset
|
418 |
(hoare_tac ctxt (simp_tac (HOL_basic_ss addsimps [@{thm "Record.K_record_comp"}] ))))) *} |
10148 | 419 |
"verification condition generator for Hoare logic" |
420 |
||
13703 | 421 |
end |