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