src/HOL/IMPP/Misc.thy
author huffman
Mon, 20 Aug 2007 19:52:52 +0200
changeset 24355 93d78fdeb55a
parent 19803 aa2581752afb
child 27148 5b78e50adc49
permissions -rw-r--r--
remove int_of_nat
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     1
(*  Title:      HOL/IMPP/Misc.thy
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     2
    ID:         $Id$
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     3
    Author:     David von Oheimb
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     4
    Copyright   1999 TUM
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
     5
*)
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
     6
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
     7
header {* Several examples for Hoare logic *}
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
     8
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
     9
theory Misc
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    10
imports Hoare
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    11
begin
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    12
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
    13
defs
17477
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    14
  newlocs_def: "newlocs       == %x. arbitrary"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    15
  setlocs_def: "setlocs s l'  == case s of st g l => st g l'"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    16
  getlocs_def: "getlocs s     == case s of st g l => l"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    17
   update_def: "update s vn v == case vn of
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    18
                               Glb gn => (case s of st g l => st (g(gn:=v)) l)
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    19
                             | Loc ln => (case s of st g l => st g (l(ln:=v)))"
ceb42ea2f223 converted to Isar theory format;
wenzelm
parents: 8177
diff changeset
    20
19803
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    21
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    22
subsection "state access"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    23
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    24
lemma getlocs_def2: "getlocs (st g l) = l"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    25
apply (unfold getlocs_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    26
apply simp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    27
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    28
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    29
lemma update_Loc_idem2 [simp]: "s[Loc Y::=s<Y>] = s"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    30
apply (unfold update_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    31
apply (induct_tac s)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    32
apply (simp add: getlocs_def2)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    33
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    34
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    35
lemma update_overwrt [simp]: "s[X::=x][X::=y] = s[X::=y]"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    36
apply (unfold update_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    37
apply (induct_tac X)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    38
apply  auto
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    39
apply  (induct_tac [!] s)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    40
apply  auto
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    41
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    42
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    43
lemma getlocs_Loc_update [simp]: "(s[Loc Y::=k])<Y'> = (if Y=Y' then k else s<Y'>)"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    44
apply (unfold update_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    45
apply (induct_tac s)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    46
apply (simp add: getlocs_def2)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    47
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    48
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    49
lemma getlocs_Glb_update [simp]: "getlocs (s[Glb Y::=k]) = getlocs s"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    50
apply (unfold update_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    51
apply (induct_tac s)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    52
apply (simp add: getlocs_def2)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    53
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    54
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    55
lemma getlocs_setlocs [simp]: "getlocs (setlocs s l) = l"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    56
apply (unfold setlocs_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    57
apply (induct_tac s)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    58
apply auto
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    59
apply (simp add: getlocs_def2)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    60
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    61
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    62
lemma getlocs_setlocs_lemma: "getlocs (setlocs s (getlocs s')[Y::=k]) = getlocs (s'[Y::=k])"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    63
apply (induct_tac Y)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    64
apply (rule_tac [2] ext)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    65
apply auto
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    66
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    67
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    68
(*unused*)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    69
lemma classic_Local_valid: 
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    70
"!v. G|={%Z s. P Z (s[Loc Y::=v]) & s<Y> = a (s[Loc Y::=v])}.  
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    71
  c .{%Z s. Q Z (s[Loc Y::=v])} ==> G|={P}. LOCAL Y:=a IN c .{Q}"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    72
apply (unfold hoare_valids_def)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    73
apply (simp (no_asm_use) add: triple_valid_def2)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    74
apply clarsimp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    75
apply (drule_tac x = "s<Y>" in spec)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    76
apply (tactic "smp_tac 1 1")
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    77
apply (drule spec)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    78
apply (drule_tac x = "s[Loc Y::=a s]" in spec)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    79
apply (simp (no_asm_use))
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    80
apply (erule (1) notE impE)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    81
apply (tactic "smp_tac 1 1")
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    82
apply simp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    83
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    84
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    85
lemma classic_Local: "!v. G|-{%Z s. P Z (s[Loc Y::=v]) & s<Y> = a (s[Loc Y::=v])}.  
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    86
  c .{%Z s. Q Z (s[Loc Y::=v])} ==> G|-{P}. LOCAL Y:=a IN c .{Q}"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    87
apply (rule export_s)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    88
(*variant 1*)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    89
apply (rule hoare_derivs.Local [THEN conseq1])
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    90
apply (erule spec)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    91
apply force
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    92
(*variant 2
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    93
by (res_inst_tac [("P'","%Z s. s' = s & P Z (s[Loc Y::=a s][Loc Y::=s'<Y>]) & (s[Loc Y::=a s])<Y> = a (s[Loc Y::=a s][Loc Y::=s'<Y>])")] conseq1 1)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    94
by  (Clarsimp_tac 2);
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    95
by (rtac hoare_derivs.Local 1);
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    96
by (etac spec 1);
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    97
*)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    98
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
    99
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   100
lemma classic_Local_indep: "[| Y~=Y'; G|-{P}. c .{%Z s. s<Y'> = d} |] ==>  
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   101
  G|-{%Z s. P Z (s[Loc Y::=a s])}. LOCAL Y:=a IN c .{%Z s. s<Y'> = d}"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   102
apply (rule classic_Local)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   103
apply clarsimp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   104
apply (erule conseq12)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   105
apply clarsimp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   106
apply (drule sym)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   107
apply simp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   108
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   109
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   110
lemma Local_indep: "[| Y~=Y'; G|-{P}. c .{%Z s. s<Y'> = d} |] ==>  
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   111
  G|-{%Z s. P Z (s[Loc Y::=a s])}. LOCAL Y:=a IN c .{%Z s. s<Y'> = d}"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   112
apply (rule export_s)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   113
apply (rule hoare_derivs.Local)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   114
apply clarsimp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   115
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   116
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   117
lemma weak_Local_indep: "[| Y'~=Y; G|-{P}. c .{%Z s. s<Y'> = d} |] ==>  
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   118
  G|-{%Z s. P Z (s[Loc Y::=a s])}. LOCAL Y:=a IN c .{%Z s. s<Y'> = d}"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   119
apply (rule weak_Local)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   120
apply auto
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   121
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   122
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   123
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   124
lemma export_Local_invariant: "G|-{%Z s. Z = s<Y>}. LOCAL Y:=a IN c .{%Z s. Z = s<Y>}"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   125
apply (rule export_s)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   126
apply (rule_tac P' = "%Z s. s'=s & True" and Q' = "%Z s. s'<Y> = s<Y>" in conseq12)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   127
prefer 2
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   128
apply  clarsimp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   129
apply (rule hoare_derivs.Local)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   130
apply clarsimp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   131
apply (rule trueI)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   132
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   133
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   134
lemma classic_Local_invariant: "G|-{%Z s. Z = s<Y>}. LOCAL Y:=a IN c .{%Z s. Z = s<Y>}"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   135
apply (rule classic_Local)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   136
apply clarsimp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   137
apply (rule trueI [THEN conseq12])
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   138
apply clarsimp
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   139
done
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   140
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   141
lemma Call_invariant: "G|-{P}. BODY pn .{%Z s. Q Z (setlocs s (getlocs s')[X::=s<Res>])} ==>  
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   142
  G|-{%Z s. s'=s & I Z (getlocs (s[X::=k Z])) & P Z (setlocs s newlocs[Loc Arg::=a s])}.  
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   143
  X:=CALL pn (a) .{%Z s. I Z (getlocs (s[X::=k Z])) & Q Z s}"
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   144
apply (rule_tac s'1 = "s'" and
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   145
  Q' = "%Z s. I Z (getlocs (s[X::=k Z])) = I Z (getlocs (s'[X::=k Z])) & Q Z s" in
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   146
  hoare_derivs.Call [THEN conseq12])
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   147
apply  (simp (no_asm_simp) add: getlocs_setlocs_lemma)
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   148
apply force
aa2581752afb removed obsolete ML files;
wenzelm
parents: 17477
diff changeset
   149
done
8177
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
   150
e59e93ad85eb added IMPP to HOL
oheimb
parents:
diff changeset
   151
end