| 1476 |      1 | (*  Title:      HOL/IMP/Hoare.thy
 | 
| 938 |      2 |     ID:         $Id$
 | 
| 1476 |      3 |     Author:     Tobias Nipkow
 | 
| 936 |      4 |     Copyright   1995 TUM
 | 
|  |      5 | *)
 | 
|  |      6 | 
 | 
| 12431 |      7 | header "Inductive Definition of Hoare Logic"
 | 
|  |      8 | 
 | 
| 35754 |      9 | theory Hoare imports Natural begin
 | 
| 1447 |     10 | 
 | 
| 12431 |     11 | types assn = "state => bool"
 | 
| 1447 |     12 | 
 | 
| 23746 |     13 | inductive
 | 
|  |     14 |   hoare :: "assn => com => assn => bool" ("|- ({(1_)}/ (_)/ {(1_)})" 50)
 | 
|  |     15 | where
 | 
| 12431 |     16 |   skip: "|- {P}\<SKIP>{P}"
 | 
| 23746 |     17 | | ass:  "|- {%s. P(s[x\<mapsto>a s])} x:==a {P}"
 | 
|  |     18 | | semi: "[| |- {P}c{Q}; |- {Q}d{R} |] ==> |- {P} c;d {R}"
 | 
|  |     19 | | If: "[| |- {%s. P s & b s}c{Q}; |- {%s. P s & ~b s}d{Q} |] ==>
 | 
| 12431 |     20 |       |- {P} \<IF> b \<THEN> c \<ELSE> d {Q}"
 | 
| 23746 |     21 | | While: "|- {%s. P s & b s} c {P} ==>
 | 
| 12431 |     22 |          |- {P} \<WHILE> b \<DO> c {%s. P s & ~b s}"
 | 
| 23746 |     23 | | conseq: "[| !s. P' s --> P s; |- {P}c{Q}; !s. Q s --> Q' s |] ==>
 | 
| 1486 |     24 |           |- {P'}c{Q'}"
 | 
| 1481 |     25 | 
 | 
| 35735 |     26 | lemma strengthen_pre: "[| !s. P' s --> P s; |- {P}c{Q} |] ==> |- {P'}c{Q}"
 | 
|  |     27 | by (blast intro: conseq)
 | 
| 12431 |     28 | 
 | 
| 35735 |     29 | lemma weaken_post: "[| |- {P}c{Q}; !s. Q s --> Q' s |] ==> |- {P}c{Q'}"
 | 
|  |     30 | by (blast intro: conseq)
 | 
| 12431 |     31 | 
 | 
| 35754 |     32 | lemma While':
 | 
|  |     33 | assumes "|- {%s. P s & b s} c {P}" and "ALL s. P s & \<not> b s \<longrightarrow> Q s"
 | 
|  |     34 | shows "|- {P} \<WHILE> b \<DO> c {Q}"
 | 
|  |     35 | by(rule weaken_post[OF While[OF assms(1)] assms(2)])
 | 
| 35735 |     36 | 
 | 
| 12431 |     37 | 
 | 
| 35754 |     38 | lemmas [simp] = skip ass semi If
 | 
| 12431 |     39 | 
 | 
| 18372 |     40 | lemmas [intro!] = hoare.skip hoare.ass hoare.semi hoare.If
 | 
| 12431 |     41 | 
 | 
| 939 |     42 | end
 |