src/HOL/IMP/Hoare.ML
author paulson
Thu Sep 26 12:47:47 1996 +0200 (1996-09-26)
changeset 2031 03a843f0f447
parent 1973 8c94c9a5be10
child 2055 cc274e47f607
permissions -rw-r--r--
Ran expandshort
clasohm@1465
     1
(*  Title:      HOL/IMP/Hoare.ML
nipkow@938
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Tobias Nipkow
nipkow@936
     4
    Copyright   1995 TUM
nipkow@936
     5
nipkow@1481
     6
Soundness (and part of) relative completeness of Hoare rules
nipkow@1481
     7
wrt denotational semantics
nipkow@936
     8
*)
nipkow@936
     9
nipkow@936
    10
open Hoare;
nipkow@936
    11
paulson@1730
    12
goalw Hoare.thy [hoare_valid_def] "!!P c Q. |- {P}c{Q} ==> |= {P}c{Q}";
paulson@1730
    13
by (etac hoare.induct 1);
nipkow@1447
    14
    by(ALLGOALS Asm_simp_tac);
nipkow@1973
    15
  by (Fast_tac 1);
paulson@1910
    16
 by (Fast_tac 1);
clasohm@1465
    17
by (rtac allI 1);
clasohm@1465
    18
by (rtac allI 1);
clasohm@1465
    19
by (rtac impI 1);
clasohm@1465
    20
by (etac induct2 1);
nipkow@1447
    21
 br Gamma_mono 1;
clasohm@1465
    22
by (rewtac Gamma_def);  
nipkow@1973
    23
by (Fast_tac 1);
paulson@1730
    24
qed "hoare_sound";
nipkow@936
    25
nipkow@1696
    26
goalw Hoare.thy [swp_def] "swp SKIP Q = Q";
paulson@2031
    27
by (Simp_tac 1);
paulson@2031
    28
by (rtac ext 1);
paulson@1910
    29
by (Fast_tac 1);
nipkow@1696
    30
qed "swp_SKIP";
nipkow@1481
    31
nipkow@1696
    32
goalw Hoare.thy [swp_def] "swp (x:=a) Q = (%s.Q(s[a s/x]))";
paulson@2031
    33
by (Simp_tac 1);
nipkow@1481
    34
qed "swp_Ass";
nipkow@1481
    35
nipkow@1481
    36
goalw Hoare.thy [swp_def] "swp (c;d) Q = swp c (swp d Q)";
paulson@2031
    37
by (Simp_tac 1);
paulson@2031
    38
by (rtac ext 1);
paulson@1910
    39
by (Fast_tac 1);
nipkow@1481
    40
qed "swp_Semi";
nipkow@936
    41
nipkow@1481
    42
goalw Hoare.thy [swp_def]
nipkow@1696
    43
  "swp (IF b THEN c ELSE d) Q = (%s. (b s --> swp c Q s) & \
nipkow@1696
    44
\                                    (~b s --> swp d Q s))";
paulson@2031
    45
by (Simp_tac 1);
paulson@2031
    46
by (rtac ext 1);
paulson@1910
    47
by (Fast_tac 1);
nipkow@1481
    48
qed "swp_If";
nipkow@936
    49
nipkow@1481
    50
goalw Hoare.thy [swp_def]
nipkow@1696
    51
  "!!s. b s ==> swp (WHILE b DO c) Q s = swp (c;WHILE b DO c) Q s";
paulson@2031
    52
by (stac C_While_If 1);
paulson@2031
    53
by (Asm_simp_tac 1);
nipkow@1481
    54
qed "swp_While_True";
nipkow@1481
    55
nipkow@1696
    56
goalw Hoare.thy [swp_def] "!!s. ~b s ==> swp (WHILE b DO c) Q s = Q s";
paulson@2031
    57
by (stac C_While_If 1);
paulson@2031
    58
by (Asm_simp_tac 1);
paulson@1910
    59
by (Fast_tac 1);
nipkow@1481
    60
qed "swp_While_False";
nipkow@1481
    61
nipkow@1696
    62
Addsimps [swp_SKIP,swp_Ass,swp_Semi,swp_If,swp_While_True,swp_While_False];
nipkow@1481
    63
paulson@1910
    64
(*Not suitable for rewriting: LOOPS!*)
paulson@1910
    65
goal Hoare.thy "swp (WHILE b DO c) Q s = \
paulson@1910
    66
\                 (if b s then swp (c;WHILE b DO c) Q s else Q s)";
paulson@1910
    67
by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
paulson@1910
    68
qed "swp_While_if";
paulson@1910
    69
paulson@1910
    70
nipkow@1481
    71
Delsimps [C_while];
nipkow@936
    72
paulson@1910
    73
AddSIs [hoare.skip, hoare.ass, hoare.semi, hoare.If];
paulson@1910
    74
nipkow@1486
    75
goal Hoare.thy "!Q. |- {swp c Q} c {Q}";
paulson@2031
    76
by (com.induct_tac "c" 1);
paulson@2031
    77
by (ALLGOALS Simp_tac);
paulson@1910
    78
by (REPEAT_FIRST Fast_tac);
paulson@1910
    79
by (deepen_tac (!claset addIs [hoare.conseq]) 0 1);
paulson@1910
    80
by (Step_tac 1);
paulson@2031
    81
by (rtac hoare.conseq 1);
nipkow@1481
    82
  be thin_rl 1;
paulson@1910
    83
  by (Fast_tac 1);
nipkow@1696
    84
 br hoare.While 1;
nipkow@1481
    85
 br hoare.conseq 1;
nipkow@1481
    86
   be thin_rl 3;
nipkow@1481
    87
   br allI 3;
nipkow@1481
    88
   br impI 3;
nipkow@1481
    89
   ba 3;
paulson@1910
    90
  by (Fast_tac 2);
nipkow@1481
    91
 by(safe_tac HOL_cs);
nipkow@1481
    92
 by(rotate_tac ~1 1);
nipkow@1481
    93
 by(Asm_full_simp_tac 1);
paulson@2031
    94
by (rotate_tac ~1 1);
paulson@2031
    95
by (Asm_full_simp_tac 1);
nipkow@1486
    96
qed_spec_mp "swp_is_pre";
nipkow@1481
    97
nipkow@1486
    98
goal Hoare.thy "!!c. |= {P}c{Q} ==> |- {P}c{Q}";
paulson@2031
    99
by (rtac (swp_is_pre RSN (2,hoare.conseq)) 1);
paulson@1910
   100
 by (Fast_tac 2);
paulson@2031
   101
by (rewrite_goals_tac [hoare_valid_def,swp_def]);
paulson@1910
   102
by (Fast_tac 1);
nipkow@1481
   103
qed "hoare_relative_complete";