3807
|
1 |
(*
|
|
2 |
File: MemoryImplementation.ML
|
|
3 |
Author: Stephan Merz
|
|
4 |
Copyright: 1997 University of Munich
|
|
5 |
|
|
6 |
RPC-Memory example: Memory implementation (ML file)
|
|
7 |
|
|
8 |
The main theorem is theorem "Implementation" at the end of this file,
|
|
9 |
which shows that the composition of a reliable memory, an RPC component, and
|
|
10 |
a memory clerk implements an unreliable memory. The files "MIsafe.ML" and
|
|
11 |
"MIlive.ML" contain lower-level lemmas for the safety and liveness parts.
|
|
12 |
|
|
13 |
Steps are (roughly) numbered as in the hand proof.
|
|
14 |
*)
|
|
15 |
|
6255
|
16 |
(* --------------------------- automatic prover --------------------------- *)
|
3807
|
17 |
|
6919
|
18 |
Delcongs [if_weak_cong];
|
|
19 |
|
6255
|
20 |
val MI_css = (claset(), simpset());
|
3807
|
21 |
|
|
22 |
(* A more aggressive variant that tries to solve subgoals by assumption
|
|
23 |
or contradiction during the simplification.
|
|
24 |
THIS IS UNSAFE, BECAUSE IT DOESN'T RECORD THE CHOICES!!
|
6255
|
25 |
(but it can be a lot faster than MI_css)
|
3807
|
26 |
*)
|
|
27 |
val MI_fast_css =
|
|
28 |
let
|
|
29 |
val (cs,ss) = MI_css
|
|
30 |
in
|
7570
|
31 |
(cs addSEs [squareE], ss addSSolver (mk_solver "" (fn thms => assume_tac ORELSE' (etac notE))))
|
3807
|
32 |
end;
|
|
33 |
|
6255
|
34 |
val temp_elim = make_elim o temp_use;
|
3807
|
35 |
|
|
36 |
(****************************** The history variable ******************************)
|
|
37 |
section "History variable";
|
|
38 |
|
|
39 |
qed_goal "HistoryLemma" MemoryImplementation.thy
|
6255
|
40 |
"|- Init(!p. ImpInit p) & [](!p. ImpNext p) \
|
|
41 |
\ --> (EEX rmhist. Init(! p. HInit rmhist p) \
|
|
42 |
\ & [](!p. [HNext rmhist p]_(c p, r p, m p, rmhist!p)))"
|
|
43 |
(fn _ => [Clarsimp_tac 1,
|
|
44 |
rtac historyI 1, TRYALL atac, rtac MI_base 1,
|
4089
|
45 |
action_simp_tac (simpset() addsimps [HInit_def]) [] [] 1,
|
6255
|
46 |
etac fun_cong 1,
|
4089
|
47 |
action_simp_tac (simpset() addsimps [HNext_def]) [busy_squareI] [] 1,
|
6255
|
48 |
etac fun_cong 1
|
3807
|
49 |
]);
|
|
50 |
|
|
51 |
qed_goal "History" MemoryImplementation.thy
|
6255
|
52 |
"|- Implementation --> (EEX rmhist. Hist rmhist)"
|
|
53 |
(fn _ => [Clarsimp_tac 1,
|
|
54 |
rtac ((temp_use HistoryLemma) RS eex_mono) 1,
|
|
55 |
force_tac (MI_css
|
|
56 |
addsimps2 [Hist_def,HistP_def,Init_def,all_box,split_box_conj]) 3,
|
|
57 |
auto_tac (MI_css
|
|
58 |
addsimps2 [Implementation_def,MClkISpec_def,RPCISpec_def,IRSpec_def,
|
|
59 |
MClkIPSpec_def,RPCIPSpec_def,RPSpec_def,
|
|
60 |
ImpInit_def,Init_def,ImpNext_def,
|
|
61 |
c_def,r_def,m_def,all_box,split_box_conj])
|
3807
|
62 |
]);
|
|
63 |
|
|
64 |
(******************************** The safety part *********************************)
|
|
65 |
|
|
66 |
section "The safety part";
|
|
67 |
|
|
68 |
(* ------------------------- Include lower-level lemmas ------------------------- *)
|
|
69 |
use "MIsafe.ML";
|
|
70 |
|
|
71 |
section "Correctness of predicate-action diagram";
|
|
72 |
|
6255
|
73 |
|
3807
|
74 |
(* ========== Step 1.1 ================================================= *)
|
|
75 |
(* The implementation's initial condition implies the state predicate S1 *)
|
|
76 |
|
|
77 |
qed_goal "Step1_1" MemoryImplementation.thy
|
6255
|
78 |
"|- ImpInit p & HInit rmhist p --> S1 rmhist p"
|
3807
|
79 |
(fn _ => [auto_tac (MI_fast_css
|
|
80 |
addsimps2 [MVNROKBA_def,MClkInit_def,RPCInit_def,PInit_def,
|
|
81 |
HInit_def,ImpInit_def,S_def,S1_def])
|
|
82 |
]);
|
|
83 |
|
|
84 |
(* ========== Step 1.2 ================================================== *)
|
|
85 |
(* Figure 16 is a predicate-action diagram for the implementation. *)
|
|
86 |
|
|
87 |
qed_goal "Step1_2_1" MemoryImplementation.thy
|
6255
|
88 |
"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p \
|
|
89 |
\ & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S1 rmhist p \
|
|
90 |
\ --> (S2 rmhist p)$ & ENext p & unchanged (c p, r p, m p)"
|
|
91 |
(fn _ => [action_simp_tac (simpset() addsimps [ImpNext_def]) []
|
|
92 |
(map temp_elim [S1ClerkUnch,S1RPCUnch,S1MemUnch,S1Hist]) 1,
|
|
93 |
auto_tac (MI_fast_css addSIs2 [S1Env])
|
3807
|
94 |
]);
|
|
95 |
|
|
96 |
qed_goal "Step1_2_2" MemoryImplementation.thy
|
6255
|
97 |
"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p \
|
|
98 |
\ & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S2 rmhist p \
|
|
99 |
\ --> (S3 rmhist p)$ & MClkFwd memCh crCh cst p & unchanged (e p, r p, m p, rmhist!p)"
|
|
100 |
(fn _ => [action_simp_tac (simpset() addsimps [ImpNext_def]) []
|
|
101 |
(map temp_elim [S2EnvUnch,S2RPCUnch,S2MemUnch,S2Hist]) 1,
|
|
102 |
auto_tac (MI_fast_css addSIs2 [S2Clerk,S2Forward])
|
3807
|
103 |
]);
|
|
104 |
|
|
105 |
qed_goal "Step1_2_3" MemoryImplementation.thy
|
6255
|
106 |
"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p \
|
|
107 |
\ & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S3 rmhist p \
|
|
108 |
\ --> ((S4 rmhist p)$ & RPCFwd crCh rmCh rst p & unchanged (e p, c p, m p, rmhist!p)) \
|
|
109 |
\ | ((S6 rmhist p)$ & RPCFail crCh rmCh rst p & unchanged (e p, c p, m p))"
|
|
110 |
(fn _ => [action_simp_tac (simpset() addsimps [ImpNext_def]) []
|
|
111 |
(map temp_elim [S3EnvUnch,S3ClerkUnch,S3MemUnch]) 1,
|
|
112 |
action_simp_tac (simpset()) []
|
|
113 |
(squareE::map temp_elim [S3RPC,S3Forward,S3Fail]) 1,
|
|
114 |
auto_tac (MI_css addDs2 [S3Hist])
|
3807
|
115 |
]);
|
|
116 |
|
|
117 |
qed_goal "Step1_2_4" MemoryImplementation.thy
|
6255
|
118 |
"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p \
|
|
119 |
\ & ~unchanged (e p, c p, r p, m p, rmhist!p) \
|
|
120 |
\ & $S4 rmhist p & (!l. $(MemInv mm l)) \
|
|
121 |
\ --> ((S4 rmhist p)$ & Read rmCh mm ires p & unchanged (e p, c p, r p, rmhist!p)) \
|
|
122 |
\ | ((S4 rmhist p)$ & (? l. Write rmCh mm ires p l) & unchanged (e p, c p, r p, rmhist!p)) \
|
|
123 |
\ | ((S5 rmhist p)$ & MemReturn rmCh ires p & unchanged (e p, c p, r p))"
|
|
124 |
(fn _ => [action_simp_tac (simpset() addsimps [ImpNext_def]) []
|
|
125 |
(map temp_elim [S4EnvUnch,S4ClerkUnch,S4RPCUnch]) 1,
|
|
126 |
action_simp_tac (simpset() addsimps [RNext_def]) []
|
|
127 |
(squareE::map temp_elim [S4Read,S4Write,S4Return]) 1,
|
|
128 |
auto_tac (MI_css addDs2 [S4Hist])
|
3807
|
129 |
]);
|
|
130 |
|
|
131 |
qed_goal "Step1_2_5" MemoryImplementation.thy
|
6255
|
132 |
"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p \
|
|
133 |
\ & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S5 rmhist p \
|
|
134 |
\ --> ((S6 rmhist p)$ & RPCReply crCh rmCh rst p & unchanged (e p, c p, m p)) \
|
|
135 |
\ | ((S6 rmhist p)$ & RPCFail crCh rmCh rst p & unchanged (e p, c p, m p))"
|
|
136 |
(fn _ => [action_simp_tac (simpset() addsimps [ImpNext_def]) []
|
|
137 |
(map temp_elim [S5EnvUnch,S5ClerkUnch,S5MemUnch,S5Hist]) 1,
|
|
138 |
action_simp_tac (simpset()) [] [squareE, temp_elim S5RPC] 1,
|
|
139 |
auto_tac (MI_fast_css addSDs2 [S5Reply,S5Fail])
|
3807
|
140 |
]);
|
|
141 |
|
|
142 |
qed_goal "Step1_2_6" MemoryImplementation.thy
|
6255
|
143 |
"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p \
|
|
144 |
\ & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S6 rmhist p \
|
|
145 |
\ --> ((S1 rmhist p)$ & MClkReply memCh crCh cst p & unchanged (e p, r p, m p))\
|
|
146 |
\ | ((S3 rmhist p)$ & MClkRetry memCh crCh cst p & unchanged (e p,r p,m p,rmhist!p))"
|
|
147 |
(fn _ => [action_simp_tac (simpset() addsimps [ImpNext_def]) []
|
|
148 |
(map temp_elim [S6EnvUnch,S6RPCUnch,S6MemUnch]) 1,
|
|
149 |
action_simp_tac (simpset()) []
|
|
150 |
(squareE::map temp_elim [S6Clerk,S6Retry,S6Reply]) 1,
|
|
151 |
auto_tac (MI_css addDs2 [S6Hist])
|
3807
|
152 |
]);
|
|
153 |
|
|
154 |
(* --------------------------------------------------------------------------
|
|
155 |
Step 1.3: S1 implies the barred initial condition.
|
|
156 |
*)
|
|
157 |
|
|
158 |
section "Initialization (Step 1.3)";
|
|
159 |
|
|
160 |
qed_goal "Step1_3" MemoryImplementation.thy
|
6255
|
161 |
"|- S1 rmhist p --> PInit (resbar rmhist) p"
|
|
162 |
(fn _ => [action_simp_tac (simpset() addsimps [resbar_def,PInit_def,S_def,S1_def])
|
3807
|
163 |
[] [] 1
|
|
164 |
]);
|
|
165 |
|
|
166 |
(* ----------------------------------------------------------------------
|
|
167 |
Step 1.4: Implementation's next-state relation simulates specification's
|
|
168 |
next-state relation (with appropriate substitutions)
|
|
169 |
*)
|
|
170 |
|
|
171 |
section "Step simulation (Step 1.4)";
|
|
172 |
|
|
173 |
qed_goal "Step1_4_1" MemoryImplementation.thy
|
6255
|
174 |
"|- ENext p & $S1 rmhist p & (S2 rmhist p)$ & unchanged (c p, r p, m p) \
|
|
175 |
\ --> unchanged (rtrner memCh!p, resbar rmhist!p)"
|
|
176 |
(fn _ => [ auto_tac (MI_fast_css addsimps2 [c_def,r_def,m_def,resbar_def]) ]);
|
3807
|
177 |
|
|
178 |
qed_goal "Step1_4_2" MemoryImplementation.thy
|
6255
|
179 |
"|- MClkFwd memCh crCh cst p & $S2 rmhist p & (S3 rmhist p)$ \
|
|
180 |
\ & unchanged (e p, r p, m p, rmhist!p) \
|
|
181 |
\ --> unchanged (rtrner memCh!p, resbar rmhist!p)"
|
|
182 |
(fn _ => [action_simp_tac
|
|
183 |
(simpset() addsimps [MClkFwd_def, e_def, r_def, m_def, resbar_def,
|
|
184 |
S_def, S2_def, S3_def]) [] [] 1
|
3807
|
185 |
]);
|
|
186 |
|
|
187 |
qed_goal "Step1_4_3a" MemoryImplementation.thy
|
6255
|
188 |
"|- RPCFwd crCh rmCh rst p & $S3 rmhist p & (S4 rmhist p)$ \
|
|
189 |
\ & unchanged (e p, c p, m p, rmhist!p) \
|
|
190 |
\ --> unchanged (rtrner memCh!p, resbar rmhist!p)"
|
|
191 |
(fn _ => [Clarsimp_tac 1,
|
|
192 |
REPEAT (dresolve_tac (map temp_use [S3_excl,S4_excl]) 1),
|
|
193 |
action_simp_tac
|
|
194 |
(simpset() addsimps [e_def,c_def,m_def,resbar_def,S_def, S3_def]) [] [] 1
|
3807
|
195 |
]);
|
|
196 |
|
|
197 |
qed_goal "Step1_4_3b" MemoryImplementation.thy
|
6255
|
198 |
"|- RPCFail crCh rmCh rst p & $S3 rmhist p & (S6 rmhist p)$ & unchanged (e p, c p, m p) \
|
|
199 |
\ --> MemFail memCh (resbar rmhist) p"
|
|
200 |
(fn _ => [Clarsimp_tac 1,
|
|
201 |
dtac (temp_use S6_excl) 1,
|
|
202 |
auto_tac (MI_css addsimps2 [RPCFail_def,MemFail_def,e_def,c_def,m_def,
|
|
203 |
resbar_def]),
|
|
204 |
force_tac (MI_css addsimps2 [S3_def,S_def]) 1,
|
|
205 |
auto_tac (MI_css addsimps2 [Return_def])
|
3807
|
206 |
]);
|
|
207 |
|
|
208 |
|
|
209 |
qed_goal "Step1_4_4a1" MemoryImplementation.thy
|
6255
|
210 |
"|- $S4 rmhist p & (S4 rmhist p)$ & ReadInner rmCh mm ires p l \
|
|
211 |
\ & unchanged (e p, c p, r p, rmhist!p) & $MemInv mm l \
|
|
212 |
\ --> ReadInner memCh mm (resbar rmhist) p l"
|
|
213 |
(fn _ => [Clarsimp_tac 1,
|
|
214 |
REPEAT (dtac (temp_use S4_excl) 1),
|
|
215 |
action_simp_tac
|
4089
|
216 |
(simpset() addsimps [ReadInner_def,GoodRead_def,BadRead_def,e_def,c_def,m_def])
|
3807
|
217 |
[] [] 1,
|
6255
|
218 |
auto_tac (MI_css addsimps2 [resbar_def]),
|
3807
|
219 |
ALLGOALS (action_simp_tac
|
4089
|
220 |
(simpset() addsimps [RPCRelayArg_def,MClkRelayArg_def,
|
3807
|
221 |
S_def,S4_def,RdRequest_def,MemInv_def])
|
|
222 |
[] [impE,MemValNotAResultE])
|
|
223 |
]);
|
|
224 |
|
|
225 |
qed_goal "Step1_4_4a" MemoryImplementation.thy
|
6255
|
226 |
"|- Read rmCh mm ires p & $S4 rmhist p & (S4 rmhist p)$ \
|
|
227 |
\ & unchanged (e p, c p, r p, rmhist!p) & (!l. $(MemInv mm l)) \
|
|
228 |
\ --> Read memCh mm (resbar rmhist) p"
|
|
229 |
(fn _ => [ force_tac (MI_css addsimps2 [Read_def] addSEs2 [Step1_4_4a1]) 1 ]);
|
3807
|
230 |
|
|
231 |
qed_goal "Step1_4_4b1" MemoryImplementation.thy
|
6255
|
232 |
"|- $S4 rmhist p & (S4 rmhist p)$ & WriteInner rmCh mm ires p l v \
|
|
233 |
\ & unchanged (e p, c p, r p, rmhist!p) \
|
|
234 |
\ --> WriteInner memCh mm (resbar rmhist) p l v"
|
|
235 |
(fn _ => [Clarsimp_tac 1,
|
|
236 |
REPEAT (dtac (temp_use S4_excl) 1),
|
|
237 |
action_simp_tac
|
4089
|
238 |
(simpset() addsimps [WriteInner_def, GoodWrite_def, BadWrite_def,
|
3807
|
239 |
e_def, c_def, m_def])
|
|
240 |
[] [] 1,
|
6255
|
241 |
auto_tac (MI_css addsimps2 [resbar_def]),
|
3807
|
242 |
ALLGOALS (action_simp_tac
|
4089
|
243 |
(simpset() addsimps [RPCRelayArg_def,MClkRelayArg_def,
|
3807
|
244 |
S_def,S4_def,WrRequest_def])
|
|
245 |
[] [])
|
|
246 |
]);
|
|
247 |
|
|
248 |
qed_goal "Step1_4_4b" MemoryImplementation.thy
|
6255
|
249 |
"|- Write rmCh mm ires p l & $S4 rmhist p & (S4 rmhist p)$ \
|
|
250 |
\ & unchanged (e p, c p, r p, rmhist!p) \
|
|
251 |
\ --> Write memCh mm (resbar rmhist) p l"
|
|
252 |
(fn _ => [ force_tac (MI_css addsimps2 [Write_def] addSEs2 [Step1_4_4b1]) 1 ]);
|
3807
|
253 |
|
|
254 |
qed_goal "Step1_4_4c" MemoryImplementation.thy
|
6255
|
255 |
"|- MemReturn rmCh ires p & $S4 rmhist p & (S5 rmhist p)$ & unchanged (e p, c p, r p) \
|
|
256 |
\ --> unchanged (rtrner memCh!p, resbar rmhist!p)"
|
3807
|
257 |
(fn _ => [action_simp_tac
|
6255
|
258 |
(simpset() addsimps [e_def,c_def,r_def,resbar_def]) [] [] 1,
|
|
259 |
REPEAT (dresolve_tac [temp_use S4_excl, temp_use S5_excl] 1),
|
3807
|
260 |
auto_tac (MI_fast_css addsimps2 [MemReturn_def,Return_def])
|
|
261 |
]);
|
|
262 |
|
|
263 |
qed_goal "Step1_4_5a" MemoryImplementation.thy
|
6255
|
264 |
"|- RPCReply crCh rmCh rst p & $S5 rmhist p & (S6 rmhist p)$ & unchanged (e p, c p, m p) \
|
|
265 |
\ --> unchanged (rtrner memCh!p, resbar rmhist!p)"
|
|
266 |
(fn _ => [Clarsimp_tac 1,
|
|
267 |
REPEAT (dresolve_tac [temp_use S5_excl, temp_use S6_excl] 1),
|
|
268 |
auto_tac (MI_css addsimps2 [e_def,c_def,m_def, resbar_def]),
|
|
269 |
auto_tac (MI_css addsimps2 [RPCReply_def,Return_def,S5_def,S_def]
|
|
270 |
addSDs2 [MVOKBAnotRF])
|
3807
|
271 |
]);
|
|
272 |
|
|
273 |
qed_goal "Step1_4_5b" MemoryImplementation.thy
|
6255
|
274 |
"|- RPCFail crCh rmCh rst p & $S5 rmhist p & (S6 rmhist p)$ & unchanged (e p, c p, m p) \
|
|
275 |
\ --> MemFail memCh (resbar rmhist) p"
|
|
276 |
(fn _ => [Clarsimp_tac 1,
|
|
277 |
dtac (temp_use S6_excl) 1,
|
|
278 |
auto_tac (MI_css addsimps2 [e_def, c_def, m_def, RPCFail_def, Return_def,
|
|
279 |
MemFail_def, resbar_def]),
|
|
280 |
auto_tac (MI_css addsimps2 [S5_def,S_def])
|
3807
|
281 |
]);
|
|
282 |
|
|
283 |
qed_goal "Step1_4_6a" MemoryImplementation.thy
|
6255
|
284 |
"|- MClkReply memCh crCh cst p & $S6 rmhist p & (S1 rmhist p)$ & unchanged (e p, r p, m p) \
|
|
285 |
\ --> MemReturn memCh (resbar rmhist) p"
|
|
286 |
(fn _ => [Clarsimp_tac 1,
|
|
287 |
dtac (temp_use S6_excl) 1,
|
|
288 |
action_simp_tac
|
4089
|
289 |
(simpset() addsimps [e_def, r_def, m_def, MClkReply_def, MemReturn_def,
|
6255
|
290 |
Return_def, resbar_def]) [] [] 1,
|
3807
|
291 |
ALLGOALS Asm_full_simp_tac, (* simplify if-then-else *)
|
|
292 |
ALLGOALS (action_simp_tac
|
4089
|
293 |
(simpset() addsimps [MClkReplyVal_def,S6_def,S_def])
|
6255
|
294 |
[] [MVOKBARFnotNR])
|
3807
|
295 |
]);
|
|
296 |
|
|
297 |
qed_goal "Step1_4_6b" MemoryImplementation.thy
|
6255
|
298 |
"|- MClkRetry memCh crCh cst p & $S6 rmhist p & (S3 rmhist p)$ \
|
|
299 |
\ & unchanged (e p, r p, m p, rmhist!p) \
|
|
300 |
\ --> MemFail memCh (resbar rmhist) p"
|
|
301 |
(fn _ => [Clarsimp_tac 1,
|
|
302 |
dtac (temp_use S3_excl) 1,
|
|
303 |
action_simp_tac
|
|
304 |
(simpset() addsimps [e_def, r_def, m_def, MClkRetry_def, MemFail_def, resbar_def])
|
3807
|
305 |
[] [] 1,
|
6255
|
306 |
auto_tac (MI_css addsimps2 [S6_def,S_def])
|
3807
|
307 |
]);
|
|
308 |
|
|
309 |
qed_goal "S_lemma" MemoryImplementation.thy
|
6255
|
310 |
"|- unchanged (e p, c p, r p, m p, rmhist!p) \
|
|
311 |
\ --> unchanged (S rmhist ec cc rc cs rs hs1 hs2 p)"
|
3807
|
312 |
(fn _ => [auto_tac (MI_css addsimps2 [e_def,c_def,r_def,m_def,caller_def,rtrner_def,
|
|
313 |
S_def,Calling_def])
|
|
314 |
]);
|
|
315 |
|
|
316 |
qed_goal "Step1_4_7H" MemoryImplementation.thy
|
6255
|
317 |
"|- unchanged (e p, c p, r p, m p, rmhist!p) \
|
|
318 |
\ --> unchanged (rtrner memCh!p, S1 rmhist p, S2 rmhist p, S3 rmhist p, \
|
|
319 |
\ S4 rmhist p, S5 rmhist p, S6 rmhist p)"
|
|
320 |
(fn _ => [Clarsimp_tac 1,
|
|
321 |
rtac conjI 1,
|
|
322 |
force_tac (MI_css addsimps2 [c_def]) 1,
|
|
323 |
force_tac (MI_css addsimps2 [S1_def,S2_def,S3_def,S4_def,S5_def,S6_def]
|
|
324 |
addSIs2 [S_lemma]) 1
|
3807
|
325 |
]);
|
|
326 |
|
|
327 |
qed_goal "Step1_4_7" MemoryImplementation.thy
|
6255
|
328 |
"|- unchanged (e p, c p, r p, m p, rmhist!p) \
|
|
329 |
\ --> unchanged (rtrner memCh!p, resbar rmhist!p, S1 rmhist p, S2 rmhist p, S3 rmhist p, \
|
|
330 |
\ S4 rmhist p, S5 rmhist p, S6 rmhist p)"
|
3807
|
331 |
(fn _ => [rtac actionI 1,
|
|
332 |
rewrite_goals_tac action_rews,
|
|
333 |
rtac impI 1,
|
6255
|
334 |
forward_tac [temp_use Step1_4_7H] 1,
|
|
335 |
auto_tac (MI_css addsimps2 [e_def,c_def,r_def,m_def,rtrner_def,resbar_def])
|
3807
|
336 |
]);
|
|
337 |
|
|
338 |
|
|
339 |
(* Frequently needed abbreviation: distinguish between idling and non-idling
|
|
340 |
steps of the implementation, and try to solve the idling case by simplification
|
|
341 |
*)
|
|
342 |
fun split_idle_tac simps i =
|
6255
|
343 |
EVERY [TRY (rtac actionI i),
|
|
344 |
case_tac "(s,t) |= unchanged (e p, c p, r p, m p, rmhist!p)" i,
|
3807
|
345 |
rewrite_goals_tac action_rews,
|
6255
|
346 |
forward_tac [temp_use Step1_4_7] i,
|
4089
|
347 |
asm_full_simp_tac (simpset() addsimps simps) i
|
3807
|
348 |
];
|
|
349 |
|
|
350 |
(* ----------------------------------------------------------------------
|
|
351 |
Combine steps 1.2 and 1.4 to prove that the implementation satisfies
|
|
352 |
the specification's next-state relation.
|
|
353 |
*)
|
|
354 |
|
|
355 |
(* Steps that leave all variables unchanged are safe, so I may assume
|
|
356 |
that some variable changes in the proof that a step is safe. *)
|
|
357 |
qed_goal "unchanged_safe" MemoryImplementation.thy
|
6255
|
358 |
"|- (~unchanged (e p, c p, r p, m p, rmhist!p) \
|
|
359 |
\ --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)) \
|
|
360 |
\ --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)"
|
|
361 |
(fn _ => [split_idle_tac [square_def] 1,
|
|
362 |
Force_tac 1
|
3807
|
363 |
]);
|
|
364 |
(* turn into (unsafe, looping!) introduction rule *)
|
6255
|
365 |
bind_thm("unchanged_safeI", impI RS (action_use unchanged_safe));
|
3807
|
366 |
|
|
367 |
qed_goal "S1safe" MemoryImplementation.thy
|
6255
|
368 |
"|- $S1 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) \
|
|
369 |
\ --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)"
|
|
370 |
(fn _ => [Clarsimp_tac 1,
|
3807
|
371 |
rtac unchanged_safeI 1,
|
|
372 |
rtac idle_squareI 1,
|
6255
|
373 |
auto_tac (MI_css addSDs2 [Step1_2_1,Step1_4_1])
|
3807
|
374 |
]);
|
|
375 |
|
|
376 |
qed_goal "S2safe" MemoryImplementation.thy
|
6255
|
377 |
"|- $S2 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) \
|
|
378 |
\ --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)"
|
|
379 |
(fn _ => [Clarsimp_tac 1,
|
3807
|
380 |
rtac unchanged_safeI 1,
|
|
381 |
rtac idle_squareI 1,
|
6255
|
382 |
auto_tac (MI_css addSDs2 [Step1_2_2,Step1_4_2])
|
3807
|
383 |
]);
|
|
384 |
|
|
385 |
qed_goal "S3safe" MemoryImplementation.thy
|
6255
|
386 |
"|- $S3 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) \
|
|
387 |
\ --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)"
|
|
388 |
(fn _ => [Clarsimp_tac 1,
|
3807
|
389 |
rtac unchanged_safeI 1,
|
6255
|
390 |
auto_tac (MI_css addSDs2 [Step1_2_3]),
|
|
391 |
auto_tac (MI_css addsimps2 [square_def,UNext_def]
|
|
392 |
addSDs2 [Step1_4_3a,Step1_4_3b])
|
3807
|
393 |
]);
|
|
394 |
|
|
395 |
qed_goal "S4safe" MemoryImplementation.thy
|
6255
|
396 |
"|- $S4 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) \
|
|
397 |
\ & (!l. $(MemInv mm l)) \
|
|
398 |
\ --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)"
|
|
399 |
(fn _ => [Clarsimp_tac 1,
|
3807
|
400 |
rtac unchanged_safeI 1,
|
6255
|
401 |
auto_tac (MI_css addSDs2 [Step1_2_4]),
|
|
402 |
auto_tac (MI_css addsimps2 [square_def,UNext_def,RNext_def]
|
|
403 |
addSDs2 [Step1_4_4a,Step1_4_4b,Step1_4_4c])
|
3807
|
404 |
]);
|
|
405 |
|
|
406 |
qed_goal "S5safe" MemoryImplementation.thy
|
6255
|
407 |
"|- $S5 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) \
|
|
408 |
\ --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)"
|
|
409 |
(fn _ => [Clarsimp_tac 1,
|
3807
|
410 |
rtac unchanged_safeI 1,
|
6255
|
411 |
auto_tac (MI_css addSDs2 [Step1_2_5]),
|
|
412 |
auto_tac (MI_css addsimps2 [square_def,UNext_def]
|
|
413 |
addSDs2 [Step1_4_5a,Step1_4_5b])
|
3807
|
414 |
]);
|
|
415 |
|
|
416 |
qed_goal "S6safe" MemoryImplementation.thy
|
6255
|
417 |
"|- $S6 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) \
|
|
418 |
\ --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)"
|
|
419 |
(fn _ => [Clarsimp_tac 1,
|
3807
|
420 |
rtac unchanged_safeI 1,
|
6255
|
421 |
auto_tac (MI_css addSDs2 [Step1_2_6]),
|
|
422 |
auto_tac (MI_css addsimps2 [square_def,UNext_def,RNext_def]
|
|
423 |
addSDs2 [Step1_4_6a,Step1_4_6b])
|
3807
|
424 |
]);
|
|
425 |
|
|
426 |
(* ----------------------------------------------------------------------
|
|
427 |
Step 1.5: Temporal refinement proof, based on previous steps.
|
|
428 |
*)
|
|
429 |
|
|
430 |
section "The liveness part";
|
|
431 |
|
|
432 |
use "MIlive.ML";
|
|
433 |
|
|
434 |
section "Refinement proof (step 1.5)";
|
|
435 |
|
|
436 |
(* Prove invariants of the implementation:
|
|
437 |
a. memory invariant
|
|
438 |
b. "implementation invariant": always in states S1,...,S6
|
|
439 |
*)
|
|
440 |
qed_goal "Step1_5_1a" MemoryImplementation.thy
|
6255
|
441 |
"|- IPImp p --> (!l. []$MemInv mm l)"
|
|
442 |
(fn _ => [auto_tac (MI_css addsimps2 [IPImp_def,box_stp_act]
|
|
443 |
addSIs2 [MemoryInvariantAll])
|
3807
|
444 |
]);
|
|
445 |
|
|
446 |
qed_goal "Step1_5_1b" MemoryImplementation.thy
|
6255
|
447 |
"|- Init(ImpInit p & HInit rmhist p) & [](ImpNext p) \
|
|
448 |
\ & [][HNext rmhist p]_(c p, r p, m p, rmhist!p) & [](!l. $MemInv mm l) \
|
|
449 |
\ --> []ImpInv rmhist p"
|
3807
|
450 |
(fn _ => [inv_tac MI_css 1,
|
6255
|
451 |
auto_tac (MI_css addsimps2 [Init_def, ImpInv_def, box_stp_act]
|
|
452 |
addSDs2 [Step1_1]
|
|
453 |
addDs2 [S1_successors,S2_successors,S3_successors,
|
|
454 |
S4_successors,S5_successors,S6_successors])
|
3807
|
455 |
]);
|
|
456 |
|
|
457 |
(*** Initialization ***)
|
|
458 |
qed_goal "Step1_5_2a" MemoryImplementation.thy
|
6255
|
459 |
"|- Init(ImpInit p & HInit rmhist p) --> Init(PInit (resbar rmhist) p)"
|
3807
|
460 |
(fn _ => [auto_tac (MI_css addsimps2 [Init_def]
|
6255
|
461 |
addSIs2 [Step1_1,Step1_3])
|
3807
|
462 |
]);
|
|
463 |
|
|
464 |
(*** step simulation ***)
|
|
465 |
qed_goal "Step1_5_2b" MemoryImplementation.thy
|
6255
|
466 |
"|- [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p) \
|
|
467 |
\ & $ImpInv rmhist p & (!l. $MemInv mm l)) \
|
|
468 |
\ --> [][UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)"
|
|
469 |
(fn _ => [auto_tac (MI_css
|
|
470 |
addsimps2 [ImpInv_def] addSEs2 [STL4E]
|
|
471 |
addSDs2 [S1safe,S2safe,S3safe,S4safe,S5safe,S6safe])
|
3807
|
472 |
]);
|
|
473 |
|
|
474 |
|
|
475 |
(*** Liveness ***)
|
|
476 |
qed_goal "GoodImpl" MemoryImplementation.thy
|
6255
|
477 |
"|- IPImp p & HistP rmhist p \
|
|
478 |
\ --> Init(ImpInit p & HInit rmhist p) \
|
|
479 |
\ & [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p)) \
|
|
480 |
\ & [](!l. $MemInv mm l) & []($ImpInv rmhist p) \
|
|
481 |
\ & ImpLive p"
|
|
482 |
(fn _ => [Clarsimp_tac 1,
|
|
483 |
subgoal_tac
|
|
484 |
"sigma |= Init(ImpInit p & HInit rmhist p) \
|
|
485 |
\ & [](ImpNext p) \
|
|
486 |
\ & [][HNext rmhist p]_(c p, r p, m p, rmhist!p) \
|
|
487 |
\ & [](!l. $MemInv mm l)" 1,
|
|
488 |
auto_tac (MI_css addsimps2 [split_box_conj,box_stp_act] addSDs2 [Step1_5_1b]),
|
|
489 |
force_tac (MI_css addsimps2 [IPImp_def,MClkIPSpec_def,RPCIPSpec_def,RPSpec_def,
|
|
490 |
ImpLive_def,c_def,r_def,m_def]) 1,
|
|
491 |
force_tac (MI_css addsimps2 [IPImp_def,MClkIPSpec_def,RPCIPSpec_def,RPSpec_def,
|
|
492 |
HistP_def,Init_def,ImpInit_def]) 1,
|
|
493 |
force_tac (MI_css addsimps2 [IPImp_def,MClkIPSpec_def,RPCIPSpec_def,RPSpec_def,
|
|
494 |
ImpNext_def,c_def,r_def,m_def,split_box_conj]) 1,
|
|
495 |
force_tac (MI_css addsimps2 [HistP_def]) 1,
|
|
496 |
force_tac (MI_css addsimps2 [temp_use allT] addSDs2 [Step1_5_1a]) 1
|
3807
|
497 |
]);
|
|
498 |
|
6255
|
499 |
(* The implementation is infinitely often in state S1... *)
|
3807
|
500 |
qed_goal "Step1_5_3a" MemoryImplementation.thy
|
6255
|
501 |
"|- [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p)) \
|
|
502 |
\ & [](!l. $MemInv mm l) \
|
|
503 |
\ & []($ImpInv rmhist p) & ImpLive p \
|
|
504 |
\ --> []<>S1 rmhist p"
|
|
505 |
(fn _ => [clarsimp_tac (MI_css addsimps2 [ImpLive_def]) 1,
|
3807
|
506 |
rtac S1Infinite 1,
|
6255
|
507 |
force_tac (MI_css
|
|
508 |
addsimps2 [split_box_conj,box_stp_act]
|
|
509 |
addSIs2 [NotS1LeadstoS6,S2_live,S3_live,S4a_live,S4b_live,S5_live]) 1,
|
|
510 |
auto_tac (MI_css addsimps2 [split_box_conj] addSIs2 [S6_live])
|
3807
|
511 |
]);
|
|
512 |
|
6255
|
513 |
(* ... which implies that it satisfies the fairness requirements of the specification *)
|
3807
|
514 |
qed_goal "Step1_5_3b" MemoryImplementation.thy
|
6255
|
515 |
"|- [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p)) \
|
|
516 |
\ & [](!l. $MemInv mm l) & []($ImpInv rmhist p) & ImpLive p \
|
|
517 |
\ --> WF(RNext memCh mm (resbar rmhist) p)_(rtrner memCh!p, resbar rmhist!p)"
|
|
518 |
(fn _ => [ auto_tac (MI_css addSIs2 [RNext_fair,Step1_5_3a]) ]);
|
3807
|
519 |
|
|
520 |
qed_goal "Step1_5_3c" MemoryImplementation.thy
|
6255
|
521 |
"|- [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p)) \
|
|
522 |
\ & [](!l. $MemInv mm l) & []($ImpInv rmhist p) & ImpLive p \
|
|
523 |
\ --> WF(MemReturn memCh (resbar rmhist) p)_(rtrner memCh!p, resbar rmhist!p)"
|
|
524 |
(fn _ => [ auto_tac (MI_css addSIs2 [Return_fair,Step1_5_3a]) ]);
|
3807
|
525 |
|
|
526 |
|
|
527 |
(* QED step of step 1 *)
|
|
528 |
qed_goal "Step1" MemoryImplementation.thy
|
6255
|
529 |
"|- IPImp p & HistP rmhist p --> UPSpec memCh mm (resbar rmhist) p"
|
3807
|
530 |
(fn _ => [auto_tac
|
|
531 |
(MI_css addsimps2 [UPSpec_def,split_box_conj]
|
6255
|
532 |
addSDs2 [GoodImpl]
|
|
533 |
addSIs2 [Step1_5_2a,Step1_5_2b,Step1_5_3b,Step1_5_3c])
|
3807
|
534 |
]);
|
|
535 |
|
|
536 |
|
|
537 |
(* ------------------------------ Step 2 ------------------------------ *)
|
|
538 |
section "Step 2";
|
|
539 |
|
|
540 |
qed_goal "Step2_2a" MemoryImplementation.thy
|
6255
|
541 |
"|- Write rmCh mm ires p l & ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p) \
|
|
542 |
\ & $ImpInv rmhist p \
|
|
543 |
\ --> (S4 rmhist p)` & unchanged (e p, c p, r p, rmhist!p)"
|
|
544 |
(fn _ => [Clarsimp_tac 1,
|
|
545 |
dtac (action_use WriteS4) 1, atac 1,
|
|
546 |
split_idle_tac [] 1,
|
|
547 |
auto_tac (MI_css addsimps2 [ImpNext_def]
|
|
548 |
addSDs2 [S4EnvUnch,S4ClerkUnch,S4RPCUnch]),
|
|
549 |
auto_tac (MI_css addsimps2 [square_def] addDs2 [S4Write])
|
3807
|
550 |
]);
|
|
551 |
|
|
552 |
qed_goal "Step2_2" MemoryImplementation.thy
|
6255
|
553 |
"|- (!p. ImpNext p) \
|
|
554 |
\ & (!p. [HNext rmhist p]_(c p, r p, m p, rmhist!p)) \
|
|
555 |
\ & (!p. $ImpInv rmhist p) \
|
|
556 |
\ & [? q. Write rmCh mm ires q l]_(mm!l) \
|
|
557 |
\ --> [? q. Write memCh mm (resbar rmhist) q l]_(mm!l)"
|
|
558 |
(fn _ => [auto_tac (MI_css addSIs2 [squareCI] addSEs2 [squareE]),
|
|
559 |
REPEAT (ares_tac [exI, action_use Step1_4_4b] 1),
|
|
560 |
force_tac (MI_css addSIs2 [WriteS4]) 1,
|
|
561 |
auto_tac (MI_css addSDs2 [Step2_2a])
|
3807
|
562 |
]);
|
|
563 |
|
|
564 |
qed_goal "Step2_lemma" MemoryImplementation.thy
|
6255
|
565 |
"|- []( (!p. ImpNext p) \
|
|
566 |
\ & (!p. [HNext rmhist p]_(c p, r p, m p, rmhist!p)) \
|
|
567 |
\ & (!p. $ImpInv rmhist p) \
|
|
568 |
\ & [? q. Write rmCh mm ires q l]_(mm!l)) \
|
|
569 |
\ --> [][? q. Write memCh mm (resbar rmhist) q l]_(mm!l)"
|
|
570 |
(fn _ => [ force_tac (MI_css addSEs2 [STL4E] addSDs2 [Step2_2]) 1 ]);
|
3807
|
571 |
|
|
572 |
qed_goal "Step2" MemoryImplementation.thy
|
6255
|
573 |
"|- #l : #MemLoc & (!p. IPImp p & HistP rmhist p) \
|
|
574 |
\ --> MSpec memCh mm (resbar rmhist) l"
|
3807
|
575 |
(fn _ => [auto_tac (MI_css addsimps2 [MSpec_def]),
|
6255
|
576 |
force_tac (MI_css addsimps2 [IPImp_def,MSpec_def]) 1,
|
|
577 |
auto_tac (MI_css addSIs2 [Step2_lemma]
|
3807
|
578 |
addsimps2 [split_box_conj,all_box]),
|
6255
|
579 |
force_tac (MI_css addsimps2 [IPImp_def,MSpec_def]) 4,
|
|
580 |
auto_tac (MI_css addsimps2 [split_box_conj] addSEs2 [allE] addSDs2 [GoodImpl])
|
3807
|
581 |
]);
|
|
582 |
|
|
583 |
(* ----------------------------- Main theorem --------------------------------- *)
|
|
584 |
section "Memory implementation";
|
|
585 |
|
|
586 |
(* The combination of a legal caller, the memory clerk, the RPC component,
|
|
587 |
and a reliable memory implement the unreliable memory.
|
|
588 |
*)
|
|
589 |
|
|
590 |
(* Implementation of internal specification by combination of implementation
|
|
591 |
and history variable with explicit refinement mapping
|
|
592 |
*)
|
|
593 |
qed_goal "Impl_IUSpec" MemoryImplementation.thy
|
6255
|
594 |
"|- Implementation & Hist rmhist --> IUSpec memCh mm (resbar rmhist)"
|
|
595 |
(fn _ => [auto_tac (MI_css addsimps2 [IUSpec_def,Implementation_def,IPImp_def,
|
|
596 |
MClkISpec_def,RPCISpec_def,IRSpec_def,Hist_def]
|
|
597 |
addSIs2 [Step1,Step2])
|
3807
|
598 |
]);
|
|
599 |
|
|
600 |
(* The main theorem: introduce hiding and eliminate history variable. *)
|
|
601 |
qed_goal "Implementation" MemoryImplementation.thy
|
6255
|
602 |
"|- Implementation --> USpec memCh"
|
|
603 |
(fn _ => [Clarsimp_tac 1,
|
|
604 |
forward_tac [temp_use History] 1,
|
3807
|
605 |
auto_tac (MI_css addsimps2 [USpec_def]
|
6255
|
606 |
addIs2 [eexI, Impl_IUSpec, MI_base]
|
3807
|
607 |
addSEs2 [eexE])
|
|
608 |
]);
|
6255
|
609 |
|
|
610 |
|