src/HOL/UNITY/SubstAx.thy
 author wenzelm Thu Jul 23 22:13:42 2015 +0200 (2015-07-23) changeset 60773 d09c66a0ea10 parent 58889 5b7a9633cfa8 child 61824 dcbe9f756ae0 permissions -rw-r--r--
more symbols by default, without xsymbols mode;
1 (*  Title:      HOL/UNITY/SubstAx.thy
2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
3     Copyright   1998  University of Cambridge
5 Weak LeadsTo relation (restricted to the set of reachable states)
6 *)
8 section{*Weak Progress*}
10 theory SubstAx imports WFair Constrains begin
12 definition Ensures :: "['a set, 'a set] => 'a program set" (infixl "Ensures" 60) where
13     "A Ensures B == {F. F \<in> (reachable F \<inter> A) ensures B}"
15 definition LeadsTo :: "['a set, 'a set] => 'a program set" (infixl "LeadsTo" 60) where
16     "A LeadsTo B == {F. F \<in> (reachable F \<inter> A) leadsTo B}"
18 notation LeadsTo  (infixl "\<longmapsto>w" 60)
21 text{*Resembles the previous definition of LeadsTo*}
23      "A LeadsTo B = {F. F \<in> (reachable F \<inter> A) leadsTo (reachable F \<inter> B)}"
25 apply (blast dest: psp_stable2 intro: leadsTo_weaken)
26 done
29 subsection{*Specialized laws for handling invariants*}
31 (** Conjoining an Always property **)
34      "F \<in> Always INV ==> (F \<in> (INV \<inter> A) LeadsTo A') = (F \<in> A LeadsTo A')"
36               Int_assoc [symmetric])
39      "F \<in> Always INV ==> (F \<in> A LeadsTo (INV \<inter> A')) = (F \<in> A LeadsTo A')"
41               Int_assoc [symmetric])
43 (* [| F \<in> Always C;  F \<in> (C \<inter> A) LeadsTo A' |] ==> F \<in> A LeadsTo A' *)
46 (* [| F \<in> Always INV;  F \<in> A LeadsTo A' |] ==> F \<in> A LeadsTo (INV \<inter> A') *)
50 subsection{*Introduction rules: Basis, Trans, Union*}
55 done
58      "[| F \<in> A LeadsTo B;  F \<in> B LeadsTo C |] ==> F \<in> A LeadsTo C"
61 done
64      "(!!A. A \<in> S ==> F \<in> A LeadsTo B) ==> F \<in> (Union S) LeadsTo B"
66 apply (subst Int_Union)
68 done
71 subsection{*Derived rules*}
76 text{*Useful with cancellation, disjunction*}
78      "F \<in> A LeadsTo (A' \<union> A') ==> F \<in> A LeadsTo A'"
82      "F \<in> A LeadsTo (A' \<union> C \<union> C) ==> F \<in> A LeadsTo (A' \<union> C)"
86      "(!!i. i \<in> I ==> F \<in> (A i) LeadsTo B) ==> F \<in> (\<Union>i \<in> I. A i) LeadsTo B"
87 apply (unfold SUP_def)
89 done
91 text{*Binary union introduction rule*}
93      "[| F \<in> A LeadsTo C; F \<in> B LeadsTo C |] ==> F \<in> (A \<union> B) LeadsTo C"
94   using LeadsTo_UN [of "{A, B}" F id C] by auto
96 text{*Lets us look at the starting state*}
98      "(!!s. s \<in> A ==> F \<in> {s} LeadsTo B) ==> F \<in> A LeadsTo B"
99 by (subst UN_singleton [symmetric], rule LeadsTo_UN, blast)
101 lemma subset_imp_LeadsTo: "A \<subseteq> B ==> F \<in> A LeadsTo B"
104 done
109      "[| F \<in> A LeadsTo A';  A' \<subseteq> B' |] ==> F \<in> A LeadsTo B'"
112 done
115      "[| F \<in> A LeadsTo A';  B \<subseteq> A |]
116       ==> F \<in> B LeadsTo A'"
119 done
122      "[| F \<in> A LeadsTo A';
123          B  \<subseteq> A;   A' \<subseteq> B' |]
124       ==> F \<in> B LeadsTo B'"
128      "[| F \<in> Always C;  F \<in> A LeadsTo A';
129          C \<inter> B \<subseteq> A;   C \<inter> A' \<subseteq> B' |]
130       ==> F \<in> B LeadsTo B'"
133 (** Two theorems for "proof lattices" **)
139      "[| F \<in> A LeadsTo B;  F \<in> B LeadsTo C |]
140       ==> F \<in> (A \<union> B) LeadsTo C"
144 (** Distributive laws **)
147      "(F \<in> (A \<union> B) LeadsTo C)  = (F \<in> A LeadsTo C & F \<in> B LeadsTo C)"
151      "(F \<in> (\<Union>i \<in> I. A i) LeadsTo B)  =  (\<forall>i \<in> I. F \<in> (A i) LeadsTo B)"
155      "(F \<in> (Union S) LeadsTo B)  =  (\<forall>A \<in> S. F \<in> A LeadsTo B)"
159 (** More rules using the premise "Always INV" **)
161 lemma LeadsTo_Basis: "F \<in> A Ensures B ==> F \<in> A LeadsTo B"
164 lemma EnsuresI:
165      "[| F \<in> (A-B) Co (A \<union> B);  F \<in> transient (A-B) |]
166       ==> F \<in> A Ensures B"
167 apply (simp add: Ensures_def Constrains_eq_constrains)
168 apply (blast intro: ensuresI constrains_weaken transient_strengthen)
169 done
172      "[| F \<in> Always INV;
173          F \<in> (INV \<inter> (A-A')) Co (A \<union> A');
174          F \<in> transient (INV \<inter> (A-A')) |]
175   ==> F \<in> A LeadsTo A'"
177 apply (blast intro: EnsuresI LeadsTo_Basis Always_ConstrainsD [THEN Constrains_weaken] transient_strengthen)
178 done
180 text{*Set difference: maybe combine with @{text leadsTo_weaken_L}??
181   This is the most useful form of the "disjunction" rule*}
183      "[| F \<in> (A-B) LeadsTo C;  F \<in> (A \<inter> B) LeadsTo C |]
184       ==> F \<in> A LeadsTo C"
189      "(!! i. i \<in> I ==> F \<in> (A i) LeadsTo (A' i))
190       ==> F \<in> (\<Union>i \<in> I. A i) LeadsTo (\<Union>i \<in> I. A' i)"
191 apply (simp only: Union_image_eq [symmetric])
193 done
196 text{*Version with no index set*}
198      "(!!i. F \<in> (A i) LeadsTo (A' i)) ==> F \<in> (\<Union>i. A i) LeadsTo (\<Union>i. A' i)"
201 text{*Version with no index set*}
203      "\<forall>i. F \<in> (A i) LeadsTo (A' i)
204       ==> F \<in> (\<Union>i. A i) LeadsTo (\<Union>i. A' i)"
207 text{*Binary union version*}
209      "[| F \<in> A LeadsTo A'; F \<in> B LeadsTo B' |]
210             ==> F \<in> (A \<union> B) LeadsTo (A' \<union> B')"
214 (** The cancellation law **)
217      "[| F \<in> A LeadsTo (A' \<union> B); F \<in> B LeadsTo B' |]
218       ==> F \<in> A LeadsTo (A' \<union> B')"
222      "[| F \<in> A LeadsTo (A' \<union> B); F \<in> (B-A') LeadsTo B' |]
223       ==> F \<in> A LeadsTo (A' \<union> B')"
225 prefer 2 apply assumption
226 apply (simp_all (no_asm_simp))
227 done
230      "[| F \<in> A LeadsTo (B \<union> A'); F \<in> B LeadsTo B' |]
231       ==> F \<in> A LeadsTo (B' \<union> A')"
234 done
237      "[| F \<in> A LeadsTo (B \<union> A'); F \<in> (B-A') LeadsTo B' |]
238       ==> F \<in> A LeadsTo (B' \<union> A')"
240 prefer 2 apply assumption
241 apply (simp_all (no_asm_simp))
242 done
245 text{*The impossibility law*}
247 text{*The set "A" may be non-empty, but it contains no reachable states*}
248 lemma LeadsTo_empty: "[|F \<in> A LeadsTo {}; all_total F|] ==> F \<in> Always (-A)"
251 done
254 subsection{*PSP: Progress-Safety-Progress*}
256 text{*Special case of PSP: Misra's "stable conjunction"*}
257 lemma PSP_Stable:
258      "[| F \<in> A LeadsTo A';  F \<in> Stable B |]
259       ==> F \<in> (A \<inter> B) LeadsTo (A' \<inter> B)"
261 apply (drule psp_stable, assumption)
263 done
265 lemma PSP_Stable2:
266      "[| F \<in> A LeadsTo A'; F \<in> Stable B |]
267       ==> F \<in> (B \<inter> A) LeadsTo (B \<inter> A')"
268 by (simp add: PSP_Stable Int_ac)
270 lemma PSP:
271      "[| F \<in> A LeadsTo A'; F \<in> B Co B' |]
272       ==> F \<in> (A \<inter> B') LeadsTo ((A' \<inter> B) \<union> (B' - B))"
274 apply (blast dest: psp intro: leadsTo_weaken)
275 done
277 lemma PSP2:
278      "[| F \<in> A LeadsTo A'; F \<in> B Co B' |]
279       ==> F \<in> (B' \<inter> A) LeadsTo ((B \<inter> A') \<union> (B' - B))"
280 by (simp add: PSP Int_ac)
282 lemma PSP_Unless:
283      "[| F \<in> A LeadsTo A'; F \<in> B Unless B' |]
284       ==> F \<in> (A \<inter> B) LeadsTo ((A' \<inter> B) \<union> B')"
285 apply (unfold Unless_def)
286 apply (drule PSP, assumption)
288 done
292      "[| F \<in> Stable A;  F \<in> transient C;
293          F \<in> Always (-A \<union> B \<union> C) |] ==> F \<in> A LeadsTo B"
296    prefer 2
297    apply (erule
300 done
303 subsection{*Induction rules*}
305 (** Meta or object quantifier ????? **)
307      "[| wf r;
308          \<forall>m. F \<in> (A \<inter> f-`{m}) LeadsTo
309                     ((A \<inter> f-`(r^-1 `` {m})) \<union> B) |]
310       ==> F \<in> A LeadsTo B"
314 done
317 lemma Bounded_induct:
318      "[| wf r;
319          \<forall>m \<in> I. F \<in> (A \<inter> f-`{m}) LeadsTo
320                       ((A \<inter> f-`(r^-1 `` {m})) \<union> B) |]
321       ==> F \<in> A LeadsTo ((A - (f-`I)) \<union> B)"
323 apply (case_tac "m \<in> I")
326 done
329 lemma LessThan_induct:
330      "(!!m::nat. F \<in> (A \<inter> f-`{m}) LeadsTo ((A \<inter> f-`(lessThan m)) \<union> B))
331       ==> F \<in> A LeadsTo B"
332 by (rule wf_less_than [THEN LeadsTo_wf_induct], auto)
334 text{*Integer version.  Could generalize from 0 to any lower bound*}
335 lemma integ_0_le_induct:
336      "[| F \<in> Always {s. (0::int) \<le> f s};
337          !! z. F \<in> (A \<inter> {s. f s = z}) LeadsTo
338                    ((A \<inter> {s. f s < z}) \<union> B) |]
339       ==> F \<in> A LeadsTo B"
340 apply (rule_tac f = "nat o f" in LessThan_induct)
343 apply (auto simp add: nat_eq_iff nat_less_iff)
344 done
346 lemma LessThan_bounded_induct:
347      "!!l::nat. \<forall>m \<in> greaterThan l.
348                    F \<in> (A \<inter> f-`{m}) LeadsTo ((A \<inter> f-`(lessThan m)) \<union> B)
349             ==> F \<in> A LeadsTo ((A \<inter> (f-`(atMost l))) \<union> B)"
350 apply (simp only: Diff_eq [symmetric] vimage_Compl
351                   Compl_greaterThan [symmetric])
352 apply (rule wf_less_than [THEN Bounded_induct], simp)
353 done
355 lemma GreaterThan_bounded_induct:
356      "!!l::nat. \<forall>m \<in> lessThan l.
357                  F \<in> (A \<inter> f-`{m}) LeadsTo ((A \<inter> f-`(greaterThan m)) \<union> B)
358       ==> F \<in> A LeadsTo ((A \<inter> (f-`(atLeast l))) \<union> B)"
359 apply (rule_tac f = f and f1 = "%k. l - k"
360        in wf_less_than [THEN wf_inv_image, THEN LeadsTo_wf_induct])
361 apply (simp add: Image_singleton, clarify)
362 apply (case_tac "m<l")
363  apply (blast intro: LeadsTo_weaken_R diff_less_mono2)
364 apply (blast intro: not_leE subset_imp_LeadsTo)
365 done
368 subsection{*Completion: Binary and General Finite versions*}
370 lemma Completion:
371      "[| F \<in> A LeadsTo (A' \<union> C);  F \<in> A' Co (A' \<union> C);
372          F \<in> B LeadsTo (B' \<union> C);  F \<in> B' Co (B' \<union> C) |]
373       ==> F \<in> (A \<inter> B) LeadsTo ((A' \<inter> B') \<union> C)"
375 apply (blast intro: completion leadsTo_weaken)
376 done
378 lemma Finite_completion_lemma:
379      "finite I
380       ==> (\<forall>i \<in> I. F \<in> (A i) LeadsTo (A' i \<union> C)) -->
381           (\<forall>i \<in> I. F \<in> (A' i) Co (A' i \<union> C)) -->
382           F \<in> (\<Inter>i \<in> I. A i) LeadsTo ((\<Inter>i \<in> I. A' i) \<union> C)"
383 apply (erule finite_induct, auto)
384 apply (rule Completion)
385    prefer 4
386    apply (simp only: INT_simps [symmetric])
387    apply (rule Constrains_INT, auto)
388 done
390 lemma Finite_completion:
391      "[| finite I;
392          !!i. i \<in> I ==> F \<in> (A i) LeadsTo (A' i \<union> C);
393          !!i. i \<in> I ==> F \<in> (A' i) Co (A' i \<union> C) |]
394       ==> F \<in> (\<Inter>i \<in> I. A i) LeadsTo ((\<Inter>i \<in> I. A' i) \<union> C)"
395 by (blast intro: Finite_completion_lemma [THEN mp, THEN mp])
397 lemma Stable_completion:
398      "[| F \<in> A LeadsTo A';  F \<in> Stable A';
399          F \<in> B LeadsTo B';  F \<in> Stable B' |]
400       ==> F \<in> (A \<inter> B) LeadsTo (A' \<inter> B')"
401 apply (unfold Stable_def)
402 apply (rule_tac C1 = "{}" in Completion [THEN LeadsTo_weaken_R])
403 apply (force+)
404 done
406 lemma Finite_stable_completion:
407      "[| finite I;
408          !!i. i \<in> I ==> F \<in> (A i) LeadsTo (A' i);
409          !!i. i \<in> I ==> F \<in> Stable (A' i) |]
410       ==> F \<in> (\<Inter>i \<in> I. A i) LeadsTo (\<Inter>i \<in> I. A' i)"
411 apply (unfold Stable_def)
412 apply (rule_tac C1 = "{}" in Finite_completion [THEN LeadsTo_weaken_R])
413 apply (simp_all, blast+)
414 done
416 end