author | wenzelm |
Sun, 16 Jan 2011 15:53:03 +0100 | |
changeset 41589 | bbd861837ebc |
parent 39159 | 0dec18004e75 |
child 42018 | 878f33040280 |
permissions | -rw-r--r-- |
41589 | 1 |
(* Title: HOL/TLA/Memory/Memory.thy |
2 |
Author: Stephan Merz, University of Munich |
|
21624 | 3 |
*) |
3807 | 4 |
|
21624 | 5 |
header {* RPC-Memory example: Memory specification *} |
3807 | 6 |
|
17309 | 7 |
theory Memory |
8 |
imports MemoryParameters ProcedureInterface |
|
9 |
begin |
|
3807 | 10 |
|
11 |
types |
|
6255 | 12 |
memChType = "(memOp, Vals) channel" |
3807 | 13 |
memType = "(Locs => Vals) stfun" (* intention: MemLocs => MemVals *) |
14 |
resType = "(PrIds => Vals) stfun" |
|
15 |
||
16 |
consts |
|
17 |
(* state predicates *) |
|
18 |
MInit :: "memType => Locs => stpred" |
|
19 |
PInit :: "resType => PrIds => stpred" |
|
20 |
(* auxiliary predicates: is there a pending read/write request for |
|
21 |
some process id and location/value? *) |
|
22 |
RdRequest :: "memChType => PrIds => Locs => stpred" |
|
23 |
WrRequest :: "memChType => PrIds => Locs => Vals => stpred" |
|
24 |
||
25 |
(* actions *) |
|
26 |
GoodRead :: "memType => resType => PrIds => Locs => action" |
|
27 |
BadRead :: "memType => resType => PrIds => Locs => action" |
|
28 |
ReadInner :: "memChType => memType => resType => PrIds => Locs => action" |
|
29 |
Read :: "memChType => memType => resType => PrIds => action" |
|
30 |
GoodWrite :: "memType => resType => PrIds => Locs => Vals => action" |
|
31 |
BadWrite :: "memType => resType => PrIds => Locs => Vals => action" |
|
32 |
WriteInner :: "memChType => memType => resType => PrIds => Locs => Vals => action" |
|
33 |
Write :: "memChType => memType => resType => PrIds => Locs => action" |
|
34 |
MemReturn :: "memChType => resType => PrIds => action" |
|
35 |
MemFail :: "memChType => resType => PrIds => action" |
|
36 |
RNext :: "memChType => memType => resType => PrIds => action" |
|
37 |
UNext :: "memChType => memType => resType => PrIds => action" |
|
38 |
||
39 |
(* temporal formulas *) |
|
40 |
RPSpec :: "memChType => memType => resType => PrIds => temporal" |
|
41 |
UPSpec :: "memChType => memType => resType => PrIds => temporal" |
|
42 |
MSpec :: "memChType => memType => resType => Locs => temporal" |
|
43 |
IRSpec :: "memChType => memType => resType => temporal" |
|
44 |
IUSpec :: "memChType => memType => resType => temporal" |
|
45 |
||
46 |
RSpec :: "memChType => resType => temporal" |
|
47 |
USpec :: "memChType => temporal" |
|
48 |
||
49 |
(* memory invariant: in the paper, the invariant is hidden in the definition of |
|
17309 | 50 |
the predicate S used in the implementation proof, but it is easier to verify |
3807 | 51 |
at this level. *) |
52 |
MemInv :: "memType => Locs => stpred" |
|
53 |
||
17309 | 54 |
defs |
55 |
MInit_def: "MInit mm l == PRED mm!l = #InitVal" |
|
56 |
PInit_def: "PInit rs p == PRED rs!p = #NotAResult" |
|
3807 | 57 |
|
17309 | 58 |
RdRequest_def: "RdRequest ch p l == PRED |
6255 | 59 |
Calling ch p & (arg<ch!p> = #(read l))" |
17309 | 60 |
WrRequest_def: "WrRequest ch p l v == PRED |
6255 | 61 |
Calling ch p & (arg<ch!p> = #(write l v))" |
3807 | 62 |
(* a read that doesn't raise BadArg *) |
17309 | 63 |
GoodRead_def: "GoodRead mm rs p l == ACT |
6255 | 64 |
#l : #MemLoc & ((rs!p)$ = $(mm!l))" |
3807 | 65 |
(* a read that raises BadArg *) |
17309 | 66 |
BadRead_def: "BadRead mm rs p l == ACT |
6255 | 67 |
#l ~: #MemLoc & ((rs!p)$ = #BadArg)" |
3807 | 68 |
(* the read action with l visible *) |
17309 | 69 |
ReadInner_def: "ReadInner ch mm rs p l == ACT |
3807 | 70 |
$(RdRequest ch p l) |
6255 | 71 |
& (GoodRead mm rs p l | BadRead mm rs p l) |
72 |
& unchanged (rtrner ch ! p)" |
|
3807 | 73 |
(* the read action with l quantified *) |
17309 | 74 |
Read_def: "Read ch mm rs p == ACT (EX l. ReadInner ch mm rs p l)" |
3807 | 75 |
|
76 |
(* similar definitions for the write action *) |
|
17309 | 77 |
GoodWrite_def: "GoodWrite mm rs p l v == ACT |
6255 | 78 |
#l : #MemLoc & #v : #MemVal |
79 |
& ((mm!l)$ = #v) & ((rs!p)$ = #OK)" |
|
17309 | 80 |
BadWrite_def: "BadWrite mm rs p l v == ACT |
6255 | 81 |
~ (#l : #MemLoc & #v : #MemVal) |
82 |
& ((rs!p)$ = #BadArg) & unchanged (mm!l)" |
|
17309 | 83 |
WriteInner_def: "WriteInner ch mm rs p l v == ACT |
3807 | 84 |
$(WrRequest ch p l v) |
6255 | 85 |
& (GoodWrite mm rs p l v | BadWrite mm rs p l v) |
86 |
& unchanged (rtrner ch ! p)" |
|
17309 | 87 |
Write_def: "Write ch mm rs p l == ACT (EX v. WriteInner ch mm rs p l v)" |
3807 | 88 |
|
89 |
(* the return action *) |
|
17309 | 90 |
MemReturn_def: "MemReturn ch rs p == ACT |
6255 | 91 |
( ($(rs!p) ~= #NotAResult) |
92 |
& ((rs!p)$ = #NotAResult) |
|
93 |
& Return ch p (rs!p))" |
|
94 |
||
3807 | 95 |
(* the failure action of the unreliable memory *) |
17309 | 96 |
MemFail_def: "MemFail ch rs p == ACT |
3807 | 97 |
$(Calling ch p) |
6255 | 98 |
& ((rs!p)$ = #MemFailure) |
99 |
& unchanged (rtrner ch ! p)" |
|
100 |
(* next-state relations for reliable / unreliable memory *) |
|
17309 | 101 |
RNext_def: "RNext ch mm rs p == ACT |
6255 | 102 |
( Read ch mm rs p |
9517
f58863b1406a
tuned version by Stephan Merz (unbatchified etc.);
wenzelm
parents:
6255
diff
changeset
|
103 |
| (EX l. Write ch mm rs p l) |
6255 | 104 |
| MemReturn ch rs p)" |
17309 | 105 |
UNext_def: "UNext ch mm rs p == ACT |
6255 | 106 |
(RNext ch mm rs p | MemFail ch rs p)" |
3807 | 107 |
|
17309 | 108 |
RPSpec_def: "RPSpec ch mm rs p == TEMP |
6255 | 109 |
Init(PInit rs p) |
110 |
& [][ RNext ch mm rs p ]_(rtrner ch ! p, rs!p) |
|
111 |
& WF(RNext ch mm rs p)_(rtrner ch ! p, rs!p) |
|
112 |
& WF(MemReturn ch rs p)_(rtrner ch ! p, rs!p)" |
|
17309 | 113 |
UPSpec_def: "UPSpec ch mm rs p == TEMP |
6255 | 114 |
Init(PInit rs p) |
115 |
& [][ UNext ch mm rs p ]_(rtrner ch ! p, rs!p) |
|
116 |
& WF(RNext ch mm rs p)_(rtrner ch ! p, rs!p) |
|
117 |
& WF(MemReturn ch rs p)_(rtrner ch ! p, rs!p)" |
|
17309 | 118 |
MSpec_def: "MSpec ch mm rs l == TEMP |
6255 | 119 |
Init(MInit mm l) |
9517
f58863b1406a
tuned version by Stephan Merz (unbatchified etc.);
wenzelm
parents:
6255
diff
changeset
|
120 |
& [][ EX p. Write ch mm rs p l ]_(mm!l)" |
17309 | 121 |
IRSpec_def: "IRSpec ch mm rs == TEMP |
9517
f58863b1406a
tuned version by Stephan Merz (unbatchified etc.);
wenzelm
parents:
6255
diff
changeset
|
122 |
(ALL p. RPSpec ch mm rs p) |
f58863b1406a
tuned version by Stephan Merz (unbatchified etc.);
wenzelm
parents:
6255
diff
changeset
|
123 |
& (ALL l. #l : #MemLoc --> MSpec ch mm rs l)" |
17309 | 124 |
IUSpec_def: "IUSpec ch mm rs == TEMP |
9517
f58863b1406a
tuned version by Stephan Merz (unbatchified etc.);
wenzelm
parents:
6255
diff
changeset
|
125 |
(ALL p. UPSpec ch mm rs p) |
f58863b1406a
tuned version by Stephan Merz (unbatchified etc.);
wenzelm
parents:
6255
diff
changeset
|
126 |
& (ALL l. #l : #MemLoc --> MSpec ch mm rs l)" |
3807 | 127 |
|
17309 | 128 |
RSpec_def: "RSpec ch rs == TEMP (EEX mm. IRSpec ch mm rs)" |
129 |
USpec_def: "USpec ch == TEMP (EEX mm rs. IUSpec ch mm rs)" |
|
3807 | 130 |
|
17309 | 131 |
MemInv_def: "MemInv mm l == PRED #l : #MemLoc --> mm!l : #MemVal" |
132 |
||
21624 | 133 |
lemmas RM_action_defs = |
134 |
MInit_def PInit_def RdRequest_def WrRequest_def MemInv_def |
|
135 |
GoodRead_def BadRead_def ReadInner_def Read_def |
|
136 |
GoodWrite_def BadWrite_def WriteInner_def Write_def |
|
137 |
MemReturn_def RNext_def |
|
138 |
||
139 |
lemmas UM_action_defs = RM_action_defs MemFail_def UNext_def |
|
140 |
||
141 |
lemmas RM_temp_defs = RPSpec_def MSpec_def IRSpec_def |
|
142 |
lemmas UM_temp_defs = UPSpec_def MSpec_def IUSpec_def |
|
143 |
||
144 |
||
145 |
(* The reliable memory is an implementation of the unreliable one *) |
|
146 |
lemma ReliableImplementsUnReliable: "|- IRSpec ch mm rs --> IUSpec ch mm rs" |
|
147 |
by (force simp: UNext_def UPSpec_def IUSpec_def RM_temp_defs elim!: STL4E [temp_use] squareE) |
|
148 |
||
149 |
(* The memory spec implies the memory invariant *) |
|
150 |
lemma MemoryInvariant: "|- MSpec ch mm rs l --> [](MemInv mm l)" |
|
151 |
by (tactic {* auto_inv_tac |
|
26342 | 152 |
(@{simpset} addsimps (@{thms RM_temp_defs} @ @{thms RM_action_defs})) 1 *}) |
21624 | 153 |
|
154 |
(* The invariant is trivial for non-locations *) |
|
155 |
lemma NonMemLocInvariant: "|- #l ~: #MemLoc --> [](MemInv mm l)" |
|
156 |
by (auto simp: MemInv_def intro!: necT [temp_use]) |
|
157 |
||
158 |
lemma MemoryInvariantAll: |
|
159 |
"|- (ALL l. #l : #MemLoc --> MSpec ch mm rs l) --> (ALL l. [](MemInv mm l))" |
|
160 |
apply clarify |
|
161 |
apply (auto elim!: MemoryInvariant [temp_use] NonMemLocInvariant [temp_use]) |
|
162 |
done |
|
163 |
||
164 |
(* The memory engages in an action for process p only if there is an |
|
165 |
unanswered call from p. |
|
166 |
We need this only for the reliable memory. |
|
167 |
*) |
|
168 |
||
169 |
lemma Memoryidle: "|- ~$(Calling ch p) --> ~ RNext ch mm rs p" |
|
170 |
by (auto simp: Return_def RM_action_defs) |
|
171 |
||
172 |
(* Enabledness conditions *) |
|
173 |
||
174 |
lemma MemReturn_change: "|- MemReturn ch rs p --> <MemReturn ch rs p>_(rtrner ch ! p, rs!p)" |
|
175 |
by (force simp: MemReturn_def angle_def) |
|
176 |
||
177 |
lemma MemReturn_enabled: "!!p. basevars (rtrner ch ! p, rs!p) ==> |
|
178 |
|- Calling ch p & (rs!p ~= #NotAResult) |
|
179 |
--> Enabled (<MemReturn ch rs p>_(rtrner ch ! p, rs!p))" |
|
180 |
apply (tactic |
|
39159 | 181 |
{* action_simp_tac @{simpset} [@{thm MemReturn_change} RSN (2, @{thm enabled_mono}) ] [] 1 *}) |
21624 | 182 |
apply (tactic |
39159 | 183 |
{* action_simp_tac (@{simpset} addsimps [@{thm MemReturn_def}, @{thm Return_def}, |
184 |
@{thm rtrner_def}]) [exI] [@{thm base_enabled}, @{thm Pair_inject}] 1 *}) |
|
21624 | 185 |
done |
186 |
||
187 |
lemma ReadInner_enabled: "!!p. basevars (rtrner ch ! p, rs!p) ==> |
|
188 |
|- Calling ch p & (arg<ch!p> = #(read l)) --> Enabled (ReadInner ch mm rs p l)" |
|
189 |
apply (case_tac "l : MemLoc") |
|
190 |
apply (force simp: ReadInner_def GoodRead_def BadRead_def RdRequest_def |
|
191 |
intro!: exI elim!: base_enabled [temp_use])+ |
|
192 |
done |
|
193 |
||
194 |
lemma WriteInner_enabled: "!!p. basevars (mm!l, rtrner ch ! p, rs!p) ==> |
|
195 |
|- Calling ch p & (arg<ch!p> = #(write l v)) |
|
196 |
--> Enabled (WriteInner ch mm rs p l v)" |
|
197 |
apply (case_tac "l:MemLoc & v:MemVal") |
|
198 |
apply (force simp: WriteInner_def GoodWrite_def BadWrite_def WrRequest_def |
|
199 |
intro!: exI elim!: base_enabled [temp_use])+ |
|
200 |
done |
|
201 |
||
202 |
lemma ReadResult: "|- Read ch mm rs p & (!l. $(MemInv mm l)) --> (rs!p)` ~= #NotAResult" |
|
203 |
by (force simp: Read_def ReadInner_def GoodRead_def BadRead_def MemInv_def) |
|
204 |
||
205 |
lemma WriteResult: "|- Write ch mm rs p l --> (rs!p)` ~= #NotAResult" |
|
206 |
by (auto simp: Write_def WriteInner_def GoodWrite_def BadWrite_def) |
|
207 |
||
208 |
lemma ReturnNotReadWrite: "|- (ALL l. $MemInv mm l) & MemReturn ch rs p |
|
209 |
--> ~ Read ch mm rs p & (ALL l. ~ Write ch mm rs p l)" |
|
210 |
by (auto simp: MemReturn_def dest!: WriteResult [temp_use] ReadResult [temp_use]) |
|
211 |
||
212 |
lemma RWRNext_enabled: "|- (rs!p = #NotAResult) & (!l. MemInv mm l) |
|
213 |
& Enabled (Read ch mm rs p | (? l. Write ch mm rs p l)) |
|
214 |
--> Enabled (<RNext ch mm rs p>_(rtrner ch ! p, rs!p))" |
|
215 |
by (force simp: RNext_def angle_def elim!: enabled_mono2 |
|
216 |
dest: ReadResult [temp_use] WriteResult [temp_use]) |
|
217 |
||
218 |
||
219 |
(* Combine previous lemmas: the memory can make a visible step if there is an |
|
220 |
outstanding call for which no result has been produced. |
|
221 |
*) |
|
222 |
lemma RNext_enabled: "!!p. !l. basevars (mm!l, rtrner ch!p, rs!p) ==> |
|
223 |
|- (rs!p = #NotAResult) & Calling ch p & (!l. MemInv mm l) |
|
224 |
--> Enabled (<RNext ch mm rs p>_(rtrner ch ! p, rs!p))" |
|
225 |
apply (auto simp: enabled_disj [try_rewrite] intro!: RWRNext_enabled [temp_use]) |
|
226 |
apply (case_tac "arg (ch w p)") |
|
39159 | 227 |
apply (tactic {* action_simp_tac (@{simpset} addsimps [@{thm Read_def}, |
228 |
temp_rewrite @{thm enabled_ex}]) [@{thm ReadInner_enabled}, exI] [] 1 *}) |
|
21624 | 229 |
apply (force dest: base_pair [temp_use]) |
230 |
apply (erule contrapos_np) |
|
39159 | 231 |
apply (tactic {* action_simp_tac (@{simpset} addsimps [@{thm Write_def}, |
232 |
temp_rewrite @{thm enabled_ex}]) |
|
233 |
[@{thm WriteInner_enabled}, exI] [] 1 *}) |
|
21624 | 234 |
done |
17309 | 235 |
|
3807 | 236 |
end |