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