15283
|
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
2 |
|
1335
|
3 |
<HTML><HEAD><TITLE>HOL/Hoare/ReadMe</TITLE></HEAD><BODY>
|
|
4 |
|
5646
|
5 |
<H2>Hoare Logic for a Simple WHILE Language</H2>
|
|
6 |
|
5647
|
7 |
<H3>Language and logic</H3>
|
5646
|
8 |
|
|
9 |
This directory contains an implementation of Hoare logic for a simple WHILE
|
5647
|
10 |
language. The constructs are
|
5646
|
11 |
<UL>
|
5647
|
12 |
<LI> <kbd>SKIP</kbd>
|
|
13 |
<LI> <kbd>_ := _</kbd>
|
|
14 |
<LI> <kbd>_ ; _</kbd>
|
|
15 |
<LI> <kbd>IF _ THEN _ ELSE _ FI</kbd>
|
|
16 |
<LI> <kbd>WHILE _ INV {_} DO _ OD</kbd>
|
5646
|
17 |
</UL>
|
|
18 |
Note that each WHILE-loop must be annotated with an invariant.
|
|
19 |
<P>
|
|
20 |
|
|
21 |
After loading theory Hoare, you can state goals of the form
|
|
22 |
<PRE>
|
13875
|
23 |
|- VARS x y ... {P} prog {Q}
|
5646
|
24 |
</PRE>
|
|
25 |
where <kbd>prog</kbd> is a program in the above language, <kbd>P</kbd> is the
|
5647
|
26 |
precondition, <kbd>Q</kbd> the postcondition, and <kbd>x y ...</kbd> is the
|
5646
|
27 |
list of all <i>program variables</i> in <kbd>prog</kbd>. The latter list must
|
|
28 |
be nonempty and it must include all variables that occur on the left-hand
|
5647
|
29 |
side of an assignment in <kbd>prog</kbd>. Example:
|
5646
|
30 |
<PRE>
|
|
31 |
|- VARS x. {x = a} x := x+1 {x = a+1}
|
|
32 |
</PRE>
|
|
33 |
The (normal) variable <kbd>a</kbd> is merely used to record the initial
|
5647
|
34 |
value of <kbd>x</kbd> and is not a program variable. Pre/post conditions
|
5646
|
35 |
can be arbitrary HOL formulae mentioning both program variables and normal
|
|
36 |
variables.
|
|
37 |
<P>
|
|
38 |
|
|
39 |
The implementation hides reasoning in Hoare logic completely and provides a
|
5647
|
40 |
tactic <kbd>hoare_tac</kbd> for transforming a goal in Hoare logic into an
|
|
41 |
equivalent list of verification conditions in HOL:
|
5646
|
42 |
<PRE>
|
|
43 |
by(hoare_tac tac i);
|
|
44 |
</PRE>
|
|
45 |
applies the tactic to subgoal <kbd>i</kbd> and applies the parameter
|
6364
|
46 |
<kbd>tac</kbd> (of type <kbd>int -> tactic</kbd>) to all generated
|
5647
|
47 |
verification conditions. A typical call is
|
5646
|
48 |
<PRE>
|
|
49 |
by(hoare_tac Asm_full_simp_tac 1);
|
|
50 |
</PRE>
|
5647
|
51 |
which, given the example goal above, solves it completely. For further
|
|
52 |
examples see <a href="Examples.ML">Examples.ML</a>.
|
5646
|
53 |
<P>
|
|
54 |
|
|
55 |
IMPORTANT:
|
|
56 |
This is a logic of partial correctness. You can only prove that your program
|
|
57 |
does the right thing <i>if</i> it terminates, but not <i>that</i> it
|
|
58 |
terminates.
|
|
59 |
|
5647
|
60 |
<H3>Notes on the implementation</H3>
|
1335
|
61 |
|
5647
|
62 |
The implementation loosely follows
|
|
63 |
<P>
|
1335
|
64 |
Mike Gordon.
|
|
65 |
<cite>Mechanizing Programming Logics in Higher Order Logic.</cite><BR>
|
5647
|
66 |
University of Cambridge, Computer Laboratory, TR 145, 1988.
|
|
67 |
<P>
|
|
68 |
published as
|
|
69 |
<P>
|
1335
|
70 |
Mike Gordon.
|
|
71 |
<cite>Mechanizing Programming Logics in Higher Order Logic.</cite><BR>
|
|
72 |
In
|
|
73 |
<cite>Current Trends in Hardware Verification and Automated Theorem Proving
|
|
74 |
</cite>,<BR>
|
|
75 |
edited by G. Birtwistle and P.A. Subrahmanyam, Springer-Verlag, 1989.
|
|
76 |
<P>
|
|
77 |
|
5647
|
78 |
The main differences: the state is modelled as a tuple as suggested in
|
1715
|
79 |
<P>
|
5647
|
80 |
J. von Wright and J. Hekanaho and P. Luostarinen and T. Langbacka.
|
|
81 |
<cite>Mechanizing Some Advanced Refinement Concepts</cite>.
|
|
82 |
Formal Methods in System Design, 3, 1993, 49-81.
|
|
83 |
<P>
|
|
84 |
and the embeding is deep, i.e. there is a concrete datatype of programs. The
|
|
85 |
latter is not really necessary.
|
1335
|
86 |
</BODY></HTML>
|