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