src/HOL/IMP/Hoare.thy
author krauss
Wed, 02 Feb 2011 08:47:45 +0100
changeset 41686 d8efc2490b8e
parent 41589 bbd861837ebc
child 42174 d0be2722ce9f
permissions -rw-r--r--
made SML/NJ happy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1447
diff changeset
     1
(*  Title:      HOL/IMP/Hoare.thy
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1447
diff changeset
     2
    Author:     Tobias Nipkow
936
a6d7b4084761 Hoare logic
nipkow
parents:
diff changeset
     3
*)
a6d7b4084761 Hoare logic
nipkow
parents:
diff changeset
     4
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
     5
header "Inductive Definition of Hoare Logic"
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
     6
35754
8e7dba5f00f5 Reorganized Hoare logic theories; added Hoare_Den
nipkow
parents: 35735
diff changeset
     7
theory Hoare imports Natural begin
1447
bc2c0acbbf29 Added a verified verification-condition generator.
nipkow
parents: 1374
diff changeset
     8
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
     9
types assn = "state => bool"
1447
bc2c0acbbf29 Added a verified verification-condition generator.
nipkow
parents: 1374
diff changeset
    10
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 20503
diff changeset
    11
inductive
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 20503
diff changeset
    12
  hoare :: "assn => com => assn => bool" ("|- ({(1_)}/ (_)/ {(1_)})" 50)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 20503
diff changeset
    13
where
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    14
  skip: "|- {P}\<SKIP>{P}"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 20503
diff changeset
    15
| ass:  "|- {%s. P(s[x\<mapsto>a s])} x:==a {P}"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 20503
diff changeset
    16
| semi: "[| |- {P}c{Q}; |- {Q}d{R} |] ==> |- {P} c;d {R}"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 20503
diff changeset
    17
| If: "[| |- {%s. P s & b s}c{Q}; |- {%s. P s & ~b s}d{Q} |] ==>
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    18
      |- {P} \<IF> b \<THEN> c \<ELSE> d {Q}"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 20503
diff changeset
    19
| While: "|- {%s. P s & b s} c {P} ==>
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    20
         |- {P} \<WHILE> b \<DO> c {%s. P s & ~b s}"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 20503
diff changeset
    21
| conseq: "[| !s. P' s --> P s; |- {P}c{Q}; !s. Q s --> Q' s |] ==>
1486
7b95d7b49f7a Introduced qed_spec_mp.
nipkow
parents: 1481
diff changeset
    22
          |- {P'}c{Q'}"
1481
03f096efa26d Modified datatype com.
nipkow
parents: 1476
diff changeset
    23
35735
f139a9bb6501 converted proofs to Isar
nipkow
parents: 27362
diff changeset
    24
lemma strengthen_pre: "[| !s. P' s --> P s; |- {P}c{Q} |] ==> |- {P'}c{Q}"
f139a9bb6501 converted proofs to Isar
nipkow
parents: 27362
diff changeset
    25
by (blast intro: conseq)
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    26
35735
f139a9bb6501 converted proofs to Isar
nipkow
parents: 27362
diff changeset
    27
lemma weaken_post: "[| |- {P}c{Q}; !s. Q s --> Q' s |] ==> |- {P}c{Q'}"
f139a9bb6501 converted proofs to Isar
nipkow
parents: 27362
diff changeset
    28
by (blast intro: conseq)
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    29
35754
8e7dba5f00f5 Reorganized Hoare logic theories; added Hoare_Den
nipkow
parents: 35735
diff changeset
    30
lemma While':
8e7dba5f00f5 Reorganized Hoare logic theories; added Hoare_Den
nipkow
parents: 35735
diff changeset
    31
assumes "|- {%s. P s & b s} c {P}" and "ALL s. P s & \<not> b s \<longrightarrow> Q s"
8e7dba5f00f5 Reorganized Hoare logic theories; added Hoare_Den
nipkow
parents: 35735
diff changeset
    32
shows "|- {P} \<WHILE> b \<DO> c {Q}"
8e7dba5f00f5 Reorganized Hoare logic theories; added Hoare_Den
nipkow
parents: 35735
diff changeset
    33
by(rule weaken_post[OF While[OF assms(1)] assms(2)])
35735
f139a9bb6501 converted proofs to Isar
nipkow
parents: 27362
diff changeset
    34
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    35
35754
8e7dba5f00f5 Reorganized Hoare logic theories; added Hoare_Den
nipkow
parents: 35735
diff changeset
    36
lemmas [simp] = skip ass semi If
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    37
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    38
lemmas [intro!] = hoare.skip hoare.ass hoare.semi hoare.If
12431
07ec657249e5 converted to Isar
kleing
parents: 9241
diff changeset
    39
939
534955033ed2 Added pretty-printing coments
nipkow
parents: 938
diff changeset
    40
end