src/HOL/IMPP/Hoare.thy
changeset 17477 ceb42ea2f223
parent 10834 a7897aebbffc
child 19803 aa2581752afb
     1.1 --- a/src/HOL/IMPP/Hoare.thy	Sat Sep 17 19:17:35 2005 +0200
     1.2 +++ b/src/HOL/IMPP/Hoare.thy	Sat Sep 17 20:14:30 2005 +0200
     1.3 @@ -2,98 +2,106 @@
     1.4      ID:         $Id$
     1.5      Author:     David von Oheimb
     1.6      Copyright   1999 TUM
     1.7 -
     1.8 -Inductive definition of Hoare logic for partial correctness
     1.9 -Completeness is taken relative to completeness of the underlying logic
    1.10 -Two versions of completeness proof:
    1.11 -  nested single recursion vs. simultaneous recursion in call rule
    1.12  *)
    1.13  
    1.14 -Hoare = Natural + 
    1.15 +header {* Inductive definition of Hoare logic for partial correctness *}
    1.16 +
    1.17 +theory Hoare
    1.18 +imports Natural
    1.19 +begin
    1.20 +
    1.21 +text {*
    1.22 +  Completeness is taken relative to completeness of the underlying logic.
    1.23 +
    1.24 +  Two versions of completeness proof: nested single recursion
    1.25 +  vs. simultaneous recursion in call rule
    1.26 +*}
    1.27  
    1.28  types 'a assn = "'a => state => bool"
    1.29  translations
    1.30 -      "a assn"   <= (type)"a => state => bool"
    1.31 +  "a assn"   <= (type)"a => state => bool"
    1.32  
    1.33  constdefs
    1.34    state_not_singleton :: bool
    1.35 - "state_not_singleton == ? s t::state. s ~= t" (* at least two elements *)
    1.36 +  "state_not_singleton == \<exists>s t::state. s ~= t" (* at least two elements *)
    1.37  
    1.38    peek_and    :: "'a assn => (state => bool) => 'a assn" (infixr "&>" 35)
    1.39 - "peek_and P p == %Z s. P Z s & p s"
    1.40 +  "peek_and P p == %Z s. P Z s & p s"
    1.41  
    1.42  datatype 'a triple =
    1.43 -    triple ('a assn) com ('a assn)         ("{(1_)}./ (_)/ .{(1_)}" [3,60,3] 58)
    1.44 -  
    1.45 +  triple "'a assn"  com  "'a assn"       ("{(1_)}./ (_)/ .{(1_)}" [3,60,3] 58)
    1.46 +
    1.47  consts
    1.48 -  triple_valid ::            nat => 'a triple     => bool ( "|=_:_" [0 , 58] 57)
    1.49 -  hoare_valids ::  'a triple set => 'a triple set => bool ("_||=_"  [58, 58] 57)
    1.50 -  hoare_derivs ::"('a triple set *  'a triple set)   set"
    1.51 +  triple_valid ::            "nat => 'a triple     => bool" ( "|=_:_" [0 , 58] 57)
    1.52 +  hoare_valids ::  "'a triple set => 'a triple set => bool" ("_||=_"  [58, 58] 57)
    1.53 +  hoare_derivs :: "('a triple set *  'a triple set)   set"
    1.54  syntax
    1.55 -  triples_valid::            nat => 'a triple set => bool ("||=_:_" [0 , 58] 57)
    1.56 -  hoare_valid  ::  'a triple set => 'a triple     => bool ("_|=_"   [58, 58] 57)
    1.57 -"@hoare_derivs"::  'a triple set => 'a triple set => bool ("_||-_"  [58, 58] 57)
    1.58 -"@hoare_deriv" ::  'a triple set => 'a triple     => bool ("_|-_"   [58, 58] 57)
    1.59 +  triples_valid::            "nat => 'a triple set => bool" ("||=_:_" [0 , 58] 57)
    1.60 +  hoare_valid  ::  "'a triple set => 'a triple     => bool" ("_|=_"   [58, 58] 57)
    1.61 +"@hoare_derivs"::  "'a triple set => 'a triple set => bool" ("_||-_"  [58, 58] 57)
    1.62 +"@hoare_deriv" ::  "'a triple set => 'a triple     => bool" ("_|-_"   [58, 58] 57)
    1.63  
    1.64 -defs triple_valid_def  "|=n:t  ==  case t of {P}.c.{Q} =>
    1.65 -		                !Z s. P Z s --> (!s'. <c,s> -n-> s' --> Q Z s')"
    1.66 +defs triple_valid_def: "|=n:t  ==  case t of {P}.c.{Q} =>
    1.67 +                                !Z s. P Z s --> (!s'. <c,s> -n-> s' --> Q Z s')"
    1.68  translations          "||=n:G" == "Ball G (triple_valid n)"
    1.69 -defs hoare_valids_def"G||=ts   ==  !n. ||=n:G --> ||=n:ts"
    1.70 +defs hoare_valids_def: "G||=ts   ==  !n. ||=n:G --> ||=n:ts"
    1.71  translations         "G |=t  " == " G||={t}"
    1.72                       "G||-ts"  == "(G,ts) : hoare_derivs"
    1.73                       "G |-t"   == " G||-{t}"
    1.74  
    1.75  (* Most General Triples *)
    1.76 -constdefs MGT    :: com => state triple              ("{=}._.{->}" [60] 58)
    1.77 +constdefs MGT    :: "com => state triple"            ("{=}._.{->}" [60] 58)
    1.78           "{=}.c.{->} == {%Z s0. Z = s0}. c .{%Z s1. <c,Z> -c-> s1}"
    1.79  
    1.80 -inductive hoare_derivs intrs
    1.81 -  
    1.82 -  empty    "G||-{}"
    1.83 -  insert"[| G |-t;  G||-ts |]
    1.84 -	==> G||-insert t ts"
    1.85 +inductive hoare_derivs intros
    1.86 +
    1.87 +  empty:    "G||-{}"
    1.88 +  insert: "[| G |-t;  G||-ts |]
    1.89 +        ==> G||-insert t ts"
    1.90  
    1.91 -  asm	   "ts <= G ==>
    1.92 -	    G||-ts" (* {P}.BODY pn.{Q} instead of (general) t for SkipD_lemma *)
    1.93 +  asm:      "ts <= G ==>
    1.94 +             G||-ts" (* {P}.BODY pn.{Q} instead of (general) t for SkipD_lemma *)
    1.95  
    1.96 -  cut   "[| G'||-ts; G||-G' |] ==> G||-ts" (* for convenience and efficiency *)
    1.97 +  cut:   "[| G'||-ts; G||-G' |] ==> G||-ts" (* for convenience and efficiency *)
    1.98  
    1.99 -  weaken"[| G||-ts' ; ts <= ts' |] ==> G||-ts"
   1.100 +  weaken: "[| G||-ts' ; ts <= ts' |] ==> G||-ts"
   1.101  
   1.102 -  conseq"!Z s. P  Z  s --> (? P' Q'. G|-{P'}.c.{Q'} &
   1.103 -                                  (!s'. (!Z'. P' Z' s --> Q' Z' s') --> Q Z s'))
   1.104 -         ==> G|-{P}.c.{Q}"
   1.105 +  conseq: "!Z s. P  Z  s --> (? P' Q'. G|-{P'}.c.{Q'} &
   1.106 +                                   (!s'. (!Z'. P' Z' s --> Q' Z' s') --> Q Z s'))
   1.107 +          ==> G|-{P}.c.{Q}"
   1.108  
   1.109  
   1.110 -  Skip	"G|-{P}. SKIP .{P}"
   1.111 +  Skip:  "G|-{P}. SKIP .{P}"
   1.112  
   1.113 -  Ass	"G|-{%Z s. P Z (s[X::=a s])}. X:==a .{P}"
   1.114 +  Ass:   "G|-{%Z s. P Z (s[X::=a s])}. X:==a .{P}"
   1.115  
   1.116 -  Local	"G|-{P}. c .{%Z s. Q Z (s[Loc X::=s'<X>])}
   1.117 -     ==> G|-{%Z s. s'=s & P Z (s[Loc X::=a s])}. LOCAL X:=a IN c .{Q}"
   1.118 +  Local: "G|-{P}. c .{%Z s. Q Z (s[Loc X::=s'<X>])}
   1.119 +      ==> G|-{%Z s. s'=s & P Z (s[Loc X::=a s])}. LOCAL X:=a IN c .{Q}"
   1.120  
   1.121 -  Comp	"[| G|-{P}.c.{Q};
   1.122 -	    G|-{Q}.d.{R} |]
   1.123 -	==> G|-{P}. (c;;d) .{R}"
   1.124 +  Comp:  "[| G|-{P}.c.{Q};
   1.125 +             G|-{Q}.d.{R} |]
   1.126 +         ==> G|-{P}. (c;;d) .{R}"
   1.127  
   1.128 -  If	"[| G|-{P &>        b }.c.{Q};
   1.129 -	    G|-{P &> (Not o b)}.d.{Q} |]
   1.130 -	==> G|-{P}. IF b THEN c ELSE d .{Q}"
   1.131 +  If:    "[| G|-{P &>        b }.c.{Q};
   1.132 +             G|-{P &> (Not o b)}.d.{Q} |]
   1.133 +         ==> G|-{P}. IF b THEN c ELSE d .{Q}"
   1.134  
   1.135 -  Loop  "G|-{P &> b}.c.{P} ==>
   1.136 -	 G|-{P}. WHILE b DO c .{P &> (Not o b)}"
   1.137 +  Loop:  "G|-{P &> b}.c.{P} ==>
   1.138 +          G|-{P}. WHILE b DO c .{P &> (Not o b)}"
   1.139  
   1.140  (*
   1.141 -  BodyN	"(insert ({P}. BODY pn  .{Q}) G)
   1.142 -	  |-{P}.  the (body pn) .{Q} ==>
   1.143 -	 G|-{P}.       BODY pn  .{Q}"
   1.144 +  BodyN: "(insert ({P}. BODY pn  .{Q}) G)
   1.145 +           |-{P}.  the (body pn) .{Q} ==>
   1.146 +          G|-{P}.       BODY pn  .{Q}"
   1.147  *)
   1.148 -  Body	"[| G Un (%p. {P p}.      BODY p  .{Q p})`Procs
   1.149 -	      ||-(%p. {P p}. the (body p) .{Q p})`Procs |]
   1.150 -	==>  G||-(%p. {P p}.      BODY p  .{Q p})`Procs"
   1.151 +  Body:  "[| G Un (%p. {P p}.      BODY p  .{Q p})`Procs
   1.152 +               ||-(%p. {P p}. the (body p) .{Q p})`Procs |]
   1.153 +         ==>  G||-(%p. {P p}.      BODY p  .{Q p})`Procs"
   1.154  
   1.155 -  Call	   "G|-{P}. BODY pn .{%Z s. Q Z (setlocs s (getlocs s')[X::=s<Res>])}
   1.156 -	==> G|-{%Z s. s'=s & P Z (setlocs s newlocs[Loc Arg::=a s])}.
   1.157 -	    X:=CALL pn(a) .{Q}"
   1.158 +  Call:     "G|-{P}. BODY pn .{%Z s. Q Z (setlocs s (getlocs s')[X::=s<Res>])}
   1.159 +         ==> G|-{%Z s. s'=s & P Z (setlocs s newlocs[Loc Arg::=a s])}.
   1.160 +             X:=CALL pn(a) .{Q}"
   1.161 +
   1.162 +ML {* use_legacy_bindings (the_context ()) *}
   1.163  
   1.164  end