author | paulson |
Thu, 30 Jan 2003 18:08:09 +0100 | |
changeset 13797 | baefae13ad37 |
parent 10834 | a7897aebbffc |
child 13798 | 4c1a53627500 |
permissions | -rw-r--r-- |
4776 | 1 |
(* Title: HOL/UNITY/UNITY |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1998 University of Cambridge |
|
5 |
||
6 |
The basic UNITY theory (revised version, based upon the "co" operator) |
|
7 |
||
8 |
From Misra, "A Logic for Concurrent Programming", 1994 |
|
9 |
*) |
|
10 |
||
13797 | 11 |
theory UNITY = Main: |
6535 | 12 |
|
13 |
typedef (Program) |
|
10064
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
14 |
'a program = "{(init:: 'a set, acts :: ('a * 'a)set set, |
13797 | 15 |
allowed :: ('a * 'a)set set). Id:acts & Id: allowed}" |
16 |
by blast |
|
6536 | 17 |
|
4776 | 18 |
constdefs |
13797 | 19 |
constrains :: "['a set, 'a set] => 'a program set" (infixl "co" 60) |
20 |
"A co B == {F. ALL act: Acts F. act``A <= B}" |
|
21 |
||
22 |
unless :: "['a set, 'a set] => 'a program set" (infixl "unless" 60) |
|
23 |
"A unless B == (A-B) co (A Un B)" |
|
24 |
||
25 |
mk_program :: "('a set * ('a * 'a)set set * ('a * 'a)set set) |
|
10064
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
26 |
=> 'a program" |
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
27 |
"mk_program == %(init, acts, allowed). |
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
28 |
Abs_Program (init, insert Id acts, insert Id allowed)" |
6535 | 29 |
|
30 |
Init :: "'a program => 'a set" |
|
10064
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
31 |
"Init F == (%(init, acts, allowed). init) (Rep_Program F)" |
6535 | 32 |
|
33 |
Acts :: "'a program => ('a * 'a)set set" |
|
10064
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
34 |
"Acts F == (%(init, acts, allowed). acts) (Rep_Program F)" |
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
35 |
|
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
36 |
AllowedActs :: "'a program => ('a * 'a)set set" |
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
37 |
"AllowedActs F == (%(init, acts, allowed). allowed) (Rep_Program F)" |
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
38 |
|
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
39 |
Allowed :: "'a program => 'a program set" |
1a77667b21ef
added compatibility relation: AllowedActs, Allowed, ok,
paulson
parents:
8948
diff
changeset
|
40 |
"Allowed F == {G. Acts G <= AllowedActs F}" |
4776 | 41 |
|
5648 | 42 |
stable :: "'a set => 'a program set" |
6536 | 43 |
"stable A == A co A" |
4776 | 44 |
|
5648 | 45 |
strongest_rhs :: "['a program, 'a set] => 'a set" |
6536 | 46 |
"strongest_rhs F A == Inter {B. F : A co B}" |
4776 | 47 |
|
5648 | 48 |
invariant :: "'a set => 'a program set" |
49 |
"invariant A == {F. Init F <= A} Int stable A" |
|
4776 | 50 |
|
5648 | 51 |
(*Polymorphic in both states and the meaning of <= *) |
6713 | 52 |
increasing :: "['a => 'b::{order}] => 'a program set" |
5648 | 53 |
"increasing f == INT z. stable {s. z <= f s}" |
4776 | 54 |
|
6536 | 55 |
|
13797 | 56 |
(*Perhaps equalities.ML shouldn't add this in the first place!*) |
57 |
declare image_Collect [simp del] |
|
58 |
||
59 |
(*** The abstract type of programs ***) |
|
60 |
||
61 |
lemmas program_typedef = |
|
62 |
Rep_Program Rep_Program_inverse Abs_Program_inverse |
|
63 |
Program_def Init_def Acts_def AllowedActs_def mk_program_def |
|
64 |
||
65 |
lemma Id_in_Acts [iff]: "Id : Acts F" |
|
66 |
apply (cut_tac x = F in Rep_Program) |
|
67 |
apply (auto simp add: program_typedef) |
|
68 |
done |
|
69 |
||
70 |
lemma insert_Id_Acts [iff]: "insert Id (Acts F) = Acts F" |
|
71 |
by (simp add: insert_absorb Id_in_Acts) |
|
72 |
||
73 |
lemma Id_in_AllowedActs [iff]: "Id : AllowedActs F" |
|
74 |
apply (cut_tac x = F in Rep_Program) |
|
75 |
apply (auto simp add: program_typedef) |
|
76 |
done |
|
77 |
||
78 |
lemma insert_Id_AllowedActs [iff]: "insert Id (AllowedActs F) = AllowedActs F" |
|
79 |
by (simp add: insert_absorb Id_in_AllowedActs) |
|
80 |
||
81 |
(** Inspectors for type "program" **) |
|
82 |
||
83 |
lemma Init_eq [simp]: "Init (mk_program (init,acts,allowed)) = init" |
|
84 |
by (auto simp add: program_typedef) |
|
85 |
||
86 |
lemma Acts_eq [simp]: "Acts (mk_program (init,acts,allowed)) = insert Id acts" |
|
87 |
by (auto simp add: program_typedef) |
|
88 |
||
89 |
lemma AllowedActs_eq [simp]: |
|
90 |
"AllowedActs (mk_program (init,acts,allowed)) = insert Id allowed" |
|
91 |
by (auto simp add: program_typedef) |
|
92 |
||
93 |
(** Equality for UNITY programs **) |
|
94 |
||
95 |
lemma surjective_mk_program [simp]: |
|
96 |
"mk_program (Init F, Acts F, AllowedActs F) = F" |
|
97 |
apply (cut_tac x = F in Rep_Program) |
|
98 |
apply (auto simp add: program_typedef) |
|
99 |
apply (drule_tac f = Abs_Program in arg_cong)+ |
|
100 |
apply (simp add: program_typedef insert_absorb) |
|
101 |
done |
|
102 |
||
103 |
lemma program_equalityI: |
|
104 |
"[| Init F = Init G; Acts F = Acts G; AllowedActs F = AllowedActs G |] |
|
105 |
==> F = G" |
|
106 |
apply (rule_tac t = F in surjective_mk_program [THEN subst]) |
|
107 |
apply (rule_tac t = G in surjective_mk_program [THEN subst], simp) |
|
108 |
done |
|
109 |
||
110 |
lemma program_equalityE: |
|
111 |
"[| F = G; |
|
112 |
[| Init F = Init G; Acts F = Acts G; AllowedActs F = AllowedActs G |] |
|
113 |
==> P |] ==> P" |
|
114 |
by simp |
|
115 |
||
116 |
lemma program_equality_iff: |
|
117 |
"(F=G) = |
|
118 |
(Init F = Init G & Acts F = Acts G &AllowedActs F = AllowedActs G)" |
|
119 |
by (blast intro: program_equalityI program_equalityE) |
|
120 |
||
121 |
||
122 |
(*** These rules allow "lazy" definition expansion |
|
123 |
They avoid expanding the full program, which is a large expression |
|
124 |
***) |
|
125 |
||
126 |
lemma def_prg_Init: "F == mk_program (init,acts,allowed) ==> Init F = init" |
|
127 |
by auto |
|
128 |
||
129 |
lemma def_prg_Acts: |
|
130 |
"F == mk_program (init,acts,allowed) ==> Acts F = insert Id acts" |
|
131 |
by auto |
|
132 |
||
133 |
lemma def_prg_AllowedActs: |
|
134 |
"F == mk_program (init,acts,allowed) |
|
135 |
==> AllowedActs F = insert Id allowed" |
|
136 |
by auto |
|
137 |
||
138 |
(*The program is not expanded, but its Init and Acts are*) |
|
139 |
lemma def_prg_simps: |
|
140 |
"[| F == mk_program (init,acts,allowed) |] |
|
141 |
==> Init F = init & Acts F = insert Id acts" |
|
142 |
by simp |
|
143 |
||
144 |
(*An action is expanded only if a pair of states is being tested against it*) |
|
145 |
lemma def_act_simp: |
|
146 |
"[| act == {(s,s'). P s s'} |] ==> ((s,s') : act) = P s s'" |
|
147 |
by auto |
|
148 |
||
149 |
(*A set is expanded only if an element is being tested against it*) |
|
150 |
lemma def_set_simp: "A == B ==> (x : A) = (x : B)" |
|
151 |
by auto |
|
152 |
||
153 |
||
154 |
(*** co ***) |
|
155 |
||
156 |
lemma constrainsI: |
|
157 |
"(!!act s s'. [| act: Acts F; (s,s') : act; s: A |] ==> s': A') |
|
158 |
==> F : A co A'" |
|
159 |
by (simp add: constrains_def, blast) |
|
160 |
||
161 |
lemma constrainsD: |
|
162 |
"[| F : A co A'; act: Acts F; (s,s'): act; s: A |] ==> s': A'" |
|
163 |
by (unfold constrains_def, blast) |
|
164 |
||
165 |
lemma constrains_empty [iff]: "F : {} co B" |
|
166 |
by (unfold constrains_def, blast) |
|
167 |
||
168 |
lemma constrains_empty2 [iff]: "(F : A co {}) = (A={})" |
|
169 |
by (unfold constrains_def, blast) |
|
170 |
||
171 |
lemma constrains_UNIV [iff]: "(F : UNIV co B) = (B = UNIV)" |
|
172 |
by (unfold constrains_def, blast) |
|
173 |
||
174 |
lemma constrains_UNIV2 [iff]: "F : A co UNIV" |
|
175 |
by (unfold constrains_def, blast) |
|
176 |
||
177 |
(*monotonic in 2nd argument*) |
|
178 |
lemma constrains_weaken_R: |
|
179 |
"[| F : A co A'; A'<=B' |] ==> F : A co B'" |
|
180 |
by (unfold constrains_def, blast) |
|
181 |
||
182 |
(*anti-monotonic in 1st argument*) |
|
183 |
lemma constrains_weaken_L: |
|
184 |
"[| F : A co A'; B<=A |] ==> F : B co A'" |
|
185 |
by (unfold constrains_def, blast) |
|
186 |
||
187 |
lemma constrains_weaken: |
|
188 |
"[| F : A co A'; B<=A; A'<=B' |] ==> F : B co B'" |
|
189 |
by (unfold constrains_def, blast) |
|
190 |
||
191 |
(** Union **) |
|
192 |
||
193 |
lemma constrains_Un: |
|
194 |
"[| F : A co A'; F : B co B' |] ==> F : (A Un B) co (A' Un B')" |
|
195 |
by (unfold constrains_def, blast) |
|
196 |
||
197 |
lemma constrains_UN: |
|
198 |
"(!!i. i:I ==> F : (A i) co (A' i)) |
|
199 |
==> F : (UN i:I. A i) co (UN i:I. A' i)" |
|
200 |
by (unfold constrains_def, blast) |
|
201 |
||
202 |
lemma constrains_Un_distrib: "(A Un B) co C = (A co C) Int (B co C)" |
|
203 |
by (unfold constrains_def, blast) |
|
204 |
||
205 |
lemma constrains_UN_distrib: "(UN i:I. A i) co B = (INT i:I. A i co B)" |
|
206 |
by (unfold constrains_def, blast) |
|
207 |
||
208 |
lemma constrains_Int_distrib: "C co (A Int B) = (C co A) Int (C co B)" |
|
209 |
by (unfold constrains_def, blast) |
|
210 |
||
211 |
lemma constrains_INT_distrib: "A co (INT i:I. B i) = (INT i:I. A co B i)" |
|
212 |
by (unfold constrains_def, blast) |
|
213 |
||
214 |
(** Intersection **) |
|
6536 | 215 |
|
13797 | 216 |
lemma constrains_Int: |
217 |
"[| F : A co A'; F : B co B' |] ==> F : (A Int B) co (A' Int B')" |
|
218 |
by (unfold constrains_def, blast) |
|
219 |
||
220 |
lemma constrains_INT: |
|
221 |
"(!!i. i:I ==> F : (A i) co (A' i)) |
|
222 |
==> F : (INT i:I. A i) co (INT i:I. A' i)" |
|
223 |
by (unfold constrains_def, blast) |
|
224 |
||
225 |
lemma constrains_imp_subset: "F : A co A' ==> A <= A'" |
|
226 |
by (unfold constrains_def, auto) |
|
227 |
||
228 |
(*The reasoning is by subsets since "co" refers to single actions |
|
229 |
only. So this rule isn't that useful.*) |
|
230 |
lemma constrains_trans: |
|
231 |
"[| F : A co B; F : B co C |] ==> F : A co C" |
|
232 |
by (unfold constrains_def, blast) |
|
233 |
||
234 |
lemma constrains_cancel: |
|
235 |
"[| F : A co (A' Un B); F : B co B' |] ==> F : A co (A' Un B')" |
|
236 |
by (unfold constrains_def, clarify, blast) |
|
237 |
||
238 |
||
239 |
(*** unless ***) |
|
240 |
||
241 |
lemma unlessI: "F : (A-B) co (A Un B) ==> F : A unless B" |
|
242 |
by (unfold unless_def, assumption) |
|
243 |
||
244 |
lemma unlessD: "F : A unless B ==> F : (A-B) co (A Un B)" |
|
245 |
by (unfold unless_def, assumption) |
|
246 |
||
247 |
||
248 |
(*** stable ***) |
|
249 |
||
250 |
lemma stableI: "F : A co A ==> F : stable A" |
|
251 |
by (unfold stable_def, assumption) |
|
252 |
||
253 |
lemma stableD: "F : stable A ==> F : A co A" |
|
254 |
by (unfold stable_def, assumption) |
|
255 |
||
256 |
lemma stable_UNIV [simp]: "stable UNIV = UNIV" |
|
257 |
by (unfold stable_def constrains_def, auto) |
|
258 |
||
259 |
(** Union **) |
|
260 |
||
261 |
lemma stable_Un: |
|
262 |
"[| F : stable A; F : stable A' |] ==> F : stable (A Un A')" |
|
263 |
||
264 |
apply (unfold stable_def) |
|
265 |
apply (blast intro: constrains_Un) |
|
266 |
done |
|
267 |
||
268 |
lemma stable_UN: |
|
269 |
"(!!i. i:I ==> F : stable (A i)) ==> F : stable (UN i:I. A i)" |
|
270 |
apply (unfold stable_def) |
|
271 |
apply (blast intro: constrains_UN) |
|
272 |
done |
|
273 |
||
274 |
(** Intersection **) |
|
275 |
||
276 |
lemma stable_Int: |
|
277 |
"[| F : stable A; F : stable A' |] ==> F : stable (A Int A')" |
|
278 |
apply (unfold stable_def) |
|
279 |
apply (blast intro: constrains_Int) |
|
280 |
done |
|
281 |
||
282 |
lemma stable_INT: |
|
283 |
"(!!i. i:I ==> F : stable (A i)) ==> F : stable (INT i:I. A i)" |
|
284 |
apply (unfold stable_def) |
|
285 |
apply (blast intro: constrains_INT) |
|
286 |
done |
|
287 |
||
288 |
lemma stable_constrains_Un: |
|
289 |
"[| F : stable C; F : A co (C Un A') |] ==> F : (C Un A) co (C Un A')" |
|
290 |
by (unfold stable_def constrains_def, blast) |
|
291 |
||
292 |
lemma stable_constrains_Int: |
|
293 |
"[| F : stable C; F : (C Int A) co A' |] ==> F : (C Int A) co (C Int A')" |
|
294 |
by (unfold stable_def constrains_def, blast) |
|
295 |
||
296 |
(*[| F : stable C; F : (C Int A) co A |] ==> F : stable (C Int A) *) |
|
297 |
lemmas stable_constrains_stable = stable_constrains_Int [THEN stableI, standard] |
|
298 |
||
299 |
||
300 |
(*** invariant ***) |
|
301 |
||
302 |
lemma invariantI: "[| Init F<=A; F: stable A |] ==> F : invariant A" |
|
303 |
by (simp add: invariant_def) |
|
304 |
||
305 |
(*Could also say "invariant A Int invariant B <= invariant (A Int B)"*) |
|
306 |
lemma invariant_Int: |
|
307 |
"[| F : invariant A; F : invariant B |] ==> F : invariant (A Int B)" |
|
308 |
by (auto simp add: invariant_def stable_Int) |
|
309 |
||
310 |
||
311 |
(*** increasing ***) |
|
312 |
||
313 |
lemma increasingD: |
|
314 |
"F : increasing f ==> F : stable {s. z <= f s}" |
|
315 |
||
316 |
by (unfold increasing_def, blast) |
|
317 |
||
318 |
lemma increasing_constant [iff]: "F : increasing (%s. c)" |
|
319 |
by (unfold increasing_def stable_def, auto) |
|
320 |
||
321 |
lemma mono_increasing_o: |
|
322 |
"mono g ==> increasing f <= increasing (g o f)" |
|
323 |
apply (unfold increasing_def stable_def constrains_def, auto) |
|
324 |
apply (blast intro: monoD order_trans) |
|
325 |
done |
|
326 |
||
327 |
(*Holds by the theorem (Suc m <= n) = (m < n) *) |
|
328 |
lemma strict_increasingD: |
|
329 |
"!!z::nat. F : increasing f ==> F: stable {s. z < f s}" |
|
330 |
by (simp add: increasing_def Suc_le_eq [symmetric]) |
|
331 |
||
332 |
||
333 |
(** The Elimination Theorem. The "free" m has become universally quantified! |
|
334 |
Should the premise be !!m instead of ALL m ? Would make it harder to use |
|
335 |
in forward proof. **) |
|
336 |
||
337 |
lemma elimination: |
|
338 |
"[| ALL m:M. F : {s. s x = m} co (B m) |] |
|
339 |
==> F : {s. s x : M} co (UN m:M. B m)" |
|
340 |
by (unfold constrains_def, blast) |
|
341 |
||
342 |
(*As above, but for the trivial case of a one-variable state, in which the |
|
343 |
state is identified with its one variable.*) |
|
344 |
lemma elimination_sing: |
|
345 |
"(ALL m:M. F : {m} co (B m)) ==> F : M co (UN m:M. B m)" |
|
346 |
by (unfold constrains_def, blast) |
|
347 |
||
348 |
||
349 |
||
350 |
(*** Theoretical Results from Section 6 ***) |
|
351 |
||
352 |
lemma constrains_strongest_rhs: |
|
353 |
"F : A co (strongest_rhs F A )" |
|
354 |
by (unfold constrains_def strongest_rhs_def, blast) |
|
355 |
||
356 |
lemma strongest_rhs_is_strongest: |
|
357 |
"F : A co B ==> strongest_rhs F A <= B" |
|
358 |
by (unfold constrains_def strongest_rhs_def, blast) |
|
359 |
||
360 |
||
361 |
(** Ad-hoc set-theory rules **) |
|
362 |
||
363 |
lemma Un_Diff_Diff [simp]: "A Un B - (A - B) = B" |
|
364 |
by blast |
|
365 |
||
366 |
lemma Int_Union_Union: "Union(B) Int A = Union((%C. C Int A)`B)" |
|
367 |
by blast |
|
368 |
||
369 |
(** Needed for WF reasoning in WFair.ML **) |
|
370 |
||
371 |
lemma Image_less_than [simp]: "less_than `` {k} = greaterThan k" |
|
372 |
by blast |
|
373 |
||
374 |
lemma Image_inverse_less_than [simp]: "less_than^-1 `` {k} = lessThan k" |
|
375 |
by blast |
|
6536 | 376 |
|
4776 | 377 |
end |