author | haftmann |
Mon, 13 Sep 2021 14:18:24 +0000 | |
changeset 74309 | 42523fbf643b |
parent 72806 | 4fa08e083865 |
permissions | -rw-r--r-- |
15283 | 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
2 |
||
15582 | 3 |
<HTML> |
4 |
||
5 |
<HEAD> |
|
6 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
|
7 |
<TITLE>HOL/Hoare/ReadMe</TITLE> |
|
8 |
</HEAD> |
|
9 |
||
10 |
<BODY> |
|
1335 | 11 |
|
5646 | 12 |
<H2>Hoare Logic for a Simple WHILE Language</H2> |
13 |
||
5647 | 14 |
<H3>Language and logic</H3> |
5646 | 15 |
|
16 |
This directory contains an implementation of Hoare logic for a simple WHILE |
|
5647 | 17 |
language. The constructs are |
5646 | 18 |
<UL> |
5647 | 19 |
<LI> <kbd>SKIP</kbd> |
20 |
<LI> <kbd>_ := _</kbd> |
|
21 |
<LI> <kbd>_ ; _</kbd> |
|
22 |
<LI> <kbd>IF _ THEN _ ELSE _ FI</kbd> |
|
23 |
<LI> <kbd>WHILE _ INV {_} DO _ OD</kbd> |
|
5646 | 24 |
</UL> |
25 |
Note that each WHILE-loop must be annotated with an invariant. |
|
26 |
<P> |
|
27 |
||
28 |
After loading theory Hoare, you can state goals of the form |
|
29 |
<PRE> |
|
15659 | 30 |
VARS x y ... {P} prog {Q} |
5646 | 31 |
</PRE> |
32 |
where <kbd>prog</kbd> is a program in the above language, <kbd>P</kbd> is the |
|
5647 | 33 |
precondition, <kbd>Q</kbd> the postcondition, and <kbd>x y ...</kbd> is the |
5646 | 34 |
list of all <i>program variables</i> in <kbd>prog</kbd>. The latter list must |
35 |
be nonempty and it must include all variables that occur on the left-hand |
|
5647 | 36 |
side of an assignment in <kbd>prog</kbd>. Example: |
5646 | 37 |
<PRE> |
15659 | 38 |
VARS x {x = a} x := x+1 {x = a+1} |
5646 | 39 |
</PRE> |
40 |
The (normal) variable <kbd>a</kbd> is merely used to record the initial |
|
5647 | 41 |
value of <kbd>x</kbd> and is not a program variable. Pre/post conditions |
5646 | 42 |
can be arbitrary HOL formulae mentioning both program variables and normal |
43 |
variables. |
|
44 |
<P> |
|
45 |
||
46 |
The implementation hides reasoning in Hoare logic completely and provides a |
|
15659 | 47 |
method <kbd>vcg</kbd> for transforming a goal in Hoare logic into an |
5647 | 48 |
equivalent list of verification conditions in HOL: |
5646 | 49 |
<PRE> |
15659 | 50 |
apply vcg |
5646 | 51 |
</PRE> |
15659 | 52 |
If you want to simplify the resulting verification conditions at the same |
53 |
time: |
|
5646 | 54 |
<PRE> |
15659 | 55 |
apply vcg_simp |
5646 | 56 |
</PRE> |
5647 | 57 |
which, given the example goal above, solves it completely. For further |
15659 | 58 |
examples see <a href="Examples.html">Examples</a>. |
5646 | 59 |
<P> |
60 |
||
61 |
IMPORTANT: |
|
62 |
This is a logic of partial correctness. You can only prove that your program |
|
63 |
does the right thing <i>if</i> it terminates, but not <i>that</i> it |
|
64 |
terminates. |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
65 |
A logic of total correctness is also provided and described below. |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
66 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
67 |
<H3>Total correctness</H3> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
68 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
69 |
To prove termination, each WHILE-loop must be annotated with a variant: |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
70 |
<UL> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
71 |
<LI> <kbd>WHILE _ INV {_} VAR {_} DO _ OD</kbd> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
72 |
</UL> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
73 |
A variant is an expression with type <kbd>nat</kbd>, which may use program |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
74 |
variables and normal variables. |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
75 |
<P> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
76 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
77 |
A total-correctness goal has the form |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
78 |
<PRE> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
79 |
VARS x y ... [P] prog [Q] |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
80 |
</PRE> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
81 |
enclosing the pre- and postcondition in square brackets. |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
82 |
<P> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
83 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
84 |
Methods <kbd>vcg_tc</kbd> and <kbd>vcg_tc_simp</kbd> can be used to derive |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
85 |
verification conditions. |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
86 |
<P> |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
87 |
|
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
88 |
From a total-correctness proof, a function can be extracted which |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
89 |
for every input satisfying the precondition returns an output |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
38353
diff
changeset
|
90 |
satisfying the postcondition. |
5646 | 91 |
|
5647 | 92 |
<H3>Notes on the implementation</H3> |
1335 | 93 |
|
5647 | 94 |
The implementation loosely follows |
95 |
<P> |
|
1335 | 96 |
Mike Gordon. |
97 |
<cite>Mechanizing Programming Logics in Higher Order Logic.</cite><BR> |
|
5647 | 98 |
University of Cambridge, Computer Laboratory, TR 145, 1988. |
99 |
<P> |
|
100 |
published as |
|
101 |
<P> |
|
1335 | 102 |
Mike Gordon. |
103 |
<cite>Mechanizing Programming Logics in Higher Order Logic.</cite><BR> |
|
104 |
In |
|
105 |
<cite>Current Trends in Hardware Verification and Automated Theorem Proving |
|
106 |
</cite>,<BR> |
|
107 |
edited by G. Birtwistle and P.A. Subrahmanyam, Springer-Verlag, 1989. |
|
108 |
<P> |
|
109 |
||
5647 | 110 |
The main differences: the state is modelled as a tuple as suggested in |
1715 | 111 |
<P> |
5647 | 112 |
J. von Wright and J. Hekanaho and P. Luostarinen and T. Langbacka. |
113 |
<cite>Mechanizing Some Advanced Refinement Concepts</cite>. |
|
114 |
Formal Methods in System Design, 3, 1993, 49-81. |
|
115 |
<P> |
|
116 |
and the embeding is deep, i.e. there is a concrete datatype of programs. The |
|
117 |
latter is not really necessary. |
|
15582 | 118 |
</BODY> |
119 |
</HTML> |