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