1 (* Title: HOL/TLA/TLA.thy
3 Copyright: 1998 University of Munich
6 header {* The temporal level of TLA *}
13 (** abstract syntax **)
14 Box :: "('w::world) form => temporal"
15 Dmd :: "('w::world) form => temporal"
16 leadsto :: "['w::world form, 'v::world form] => temporal"
17 Stable :: "stpred => temporal"
18 WF :: "[action, 'a stfun] => temporal"
19 SF :: "[action, 'a stfun] => temporal"
21 (* Quantification over (flexible) state variables *)
22 EEx :: "('a stfun => temporal) => temporal" (binder "Eex " 10)
23 AAll :: "('a stfun => temporal) => temporal" (binder "Aall " 10)
25 (** concrete syntax **)
27 "_Box" :: "lift => lift" ("([]_)" [40] 40)
28 "_Dmd" :: "lift => lift" ("(<>_)" [40] 40)
29 "_leadsto" :: "[lift,lift] => lift" ("(_ ~> _)" [23,22] 22)
30 "_stable" :: "lift => lift" ("(stable/ _)")
31 "_WF" :: "[lift,lift] => lift" ("(WF'(_')'_(_))" [0,60] 55)
32 "_SF" :: "[lift,lift] => lift" ("(SF'(_')'_(_))" [0,60] 55)
34 "_EEx" :: "[idts, lift] => lift" ("(3EEX _./ _)" [0,10] 10)
35 "_AAll" :: "[idts, lift] => lift" ("(3AALL _./ _)" [0,10] 10)
40 "_leadsto" == "CONST leadsto"
41 "_stable" == "CONST Stable"
44 "_EEx v A" == "Eex v. A"
45 "_AAll v A" == "Aall v. A"
47 "sigma |= []F" <= "_Box F sigma"
48 "sigma |= <>F" <= "_Dmd F sigma"
49 "sigma |= F ~> G" <= "_leadsto F G sigma"
50 "sigma |= stable P" <= "_stable P sigma"
51 "sigma |= WF(A)_v" <= "_WF A v sigma"
52 "sigma |= SF(A)_v" <= "_SF A v sigma"
53 "sigma |= EEX x. F" <= "_EEx x F sigma"
54 "sigma |= AALL x. F" <= "_AAll x F sigma"
57 "_Box" :: "lift => lift" ("(\<box>_)" [40] 40)
58 "_Dmd" :: "lift => lift" ("(\<diamond>_)" [40] 40)
59 "_leadsto" :: "[lift,lift] => lift" ("(_ \<leadsto> _)" [23,22] 22)
60 "_EEx" :: "[idts, lift] => lift" ("(3\<exists>\<exists> _./ _)" [0,10] 10)
61 "_AAll" :: "[idts, lift] => lift" ("(3\<forall>\<forall> _./ _)" [0,10] 10)
64 "_EEx" :: "[idts, lift] => lift" ("(3\<exists>\<exists> _./ _)" [0,10] 10)
65 "_AAll" :: "[idts, lift] => lift" ("(3\<forall>\<forall> _./ _)" [0,10] 10)
68 (* Definitions of derived operators *)
69 dmd_def: "TEMP <>F == TEMP ~[]~F"
70 boxInit: "TEMP []F == TEMP []Init F"
71 leadsto_def: "TEMP F ~> G == TEMP [](Init F --> <>G)"
72 stable_def: "TEMP stable P == TEMP []($P --> P$)"
73 WF_def: "TEMP WF(A)_v == TEMP <>[] Enabled(<A>_v) --> []<><A>_v"
74 SF_def: "TEMP SF(A)_v == TEMP []<> Enabled(<A>_v) --> []<><A>_v"
75 aall_def: "TEMP (AALL x. F x) == TEMP ~ (EEX x. ~ F x)"
77 (* Base axioms for raw TLA. *)
78 normalT: "|- [](F --> G) --> ([]F --> []G)" (* polymorphic *)
79 reflT: "|- []F --> F" (* F::temporal *)
80 transT: "|- []F --> [][]F" (* polymorphic *)
81 linT: "|- <>F & <>G --> (<>(F & <>G)) | (<>(G & <>F))"
82 discT: "|- [](F --> <>(~F & <>F)) --> (F --> []<>F)"
83 primeI: "|- []P --> Init P`"
84 primeE: "|- [](Init P --> []F) --> Init P` --> (F --> []F)"
85 indT: "|- [](Init P & ~[]F --> Init P` & F) --> Init P --> []F"
86 allT: "|- (ALL x. [](F x)) = ([](ALL x. F x))"
88 necT: "|- F ==> |- []F" (* polymorphic *)
90 (* Flexible quantification: refinement mappings, history variables *)
91 eexI: "|- F x --> (EEX x. F x)"
92 eexE: "[| sigma |= (EEX x. F x); basevars vs;
93 (!!x. [| basevars (x, vs); sigma |= F x |] ==> (G sigma)::bool)
95 history: "|- EEX h. Init(h = ha) & [](!x. $h = #x --> h` = hb x)"
98 (* Specialize intensional introduction/elimination rules for temporal formulas *)
100 lemma tempI: "(!!sigma. sigma |= (F::temporal)) ==> |- F"
102 apply (erule meta_spec)
105 lemma tempD: "|- (F::temporal) ==> sigma |= F"
109 (* ======== Functions to "unlift" temporal theorems ====== *)
112 (* The following functions are specialized versions of the corresponding
113 functions defined in theory Intensional in that they introduce a
114 "world" parameter of type "behavior".
117 (rewrite_rule @{thms action_rews} (th RS @{thm tempD})) handle THM _ => action_unlift th;
119 (* Turn |- F = G into meta-level rewrite rule F == G *)
120 val temp_rewrite = int_rewrite
123 case (concl_of th) of
124 Const _ $ (Const (@{const_name Intensional.Valid}, _) $ _) =>
125 ((flatten (temp_unlift th)) handle THM _ => th)
128 fun try_rewrite th = temp_rewrite th handle THM _ => temp_use th;
131 attribute_setup temp_unlift = {* Scan.succeed (Thm.rule_attribute (K temp_unlift)) *}
132 attribute_setup temp_rewrite = {* Scan.succeed (Thm.rule_attribute (K temp_rewrite)) *}
133 attribute_setup temp_use = {* Scan.succeed (Thm.rule_attribute (K temp_use)) *}
134 attribute_setup try_rewrite = {* Scan.succeed (Thm.rule_attribute (K try_rewrite)) *}
137 (* Update classical reasoner---will be updated once more below! *)
139 declare tempI [intro!]
142 (* Modify the functions that add rules to simpsets, classical sets,
143 and clasimpsets in order to accept "lifted" theorems
146 (* ------------------------------------------------------------------------- *)
147 (*** "Simple temporal logic": only [] and <> ***)
148 (* ------------------------------------------------------------------------- *)
149 section "Simple temporal logic"
151 (* []~F == []~Init F *)
152 lemmas boxNotInit = boxInit [of "LIFT ~F", unfolded Init_simps] for F
154 lemma dmdInit: "TEMP <>F == TEMP <> Init F"
155 apply (unfold dmd_def)
156 apply (unfold boxInit [of "LIFT ~F"])
157 apply (simp (no_asm) add: Init_simps)
160 lemmas dmdNotInit = dmdInit [of "LIFT ~F", unfolded Init_simps] for F
162 (* boxInit and dmdInit cannot be used as rewrites, because they loop.
163 Non-looping instances for state predicates and actions are occasionally useful.
165 lemmas boxInit_stp = boxInit [where 'a = state]
166 lemmas boxInit_act = boxInit [where 'a = "state * state"]
167 lemmas dmdInit_stp = dmdInit [where 'a = state]
168 lemmas dmdInit_act = dmdInit [where 'a = "state * state"]
170 (* The symmetric equations can be used to get rid of Init *)
171 lemmas boxInitD = boxInit [symmetric]
172 lemmas dmdInitD = dmdInit [symmetric]
173 lemmas boxNotInitD = boxNotInit [symmetric]
174 lemmas dmdNotInitD = dmdNotInit [symmetric]
176 lemmas Init_simps = Init_simps boxInitD dmdInitD boxNotInitD dmdNotInitD
178 (* ------------------------ STL2 ------------------------------------------- *)
181 (* The "polymorphic" (generic) variant *)
182 lemma STL2_gen: "|- []F --> Init F"
183 apply (unfold boxInit [of F])
187 (* see also STL2_pr below: "|- []P --> Init P & Init (P`)" *)
190 (* Dual versions for <> *)
191 lemma InitDmd: "|- F --> <> F"
192 apply (unfold dmd_def)
193 apply (auto dest!: STL2 [temp_use])
196 lemma InitDmd_gen: "|- Init F --> <>F"
198 apply (drule InitDmd [temp_use])
199 apply (simp add: dmdInitD)
203 (* ------------------------ STL3 ------------------------------------------- *)
204 lemma STL3: "|- ([][]F) = ([]F)"
205 by (auto elim: transT [temp_use] STL2 [temp_use])
207 (* corresponding elimination rule introduces double boxes:
208 [| (sigma |= []F); (sigma |= [][]F) ==> PROP W |] ==> PROP W
210 lemmas dup_boxE = STL3 [temp_unlift, THEN iffD2, elim_format]
211 lemmas dup_boxD = STL3 [temp_unlift, THEN iffD1]
213 (* dual versions for <> *)
214 lemma DmdDmd: "|- (<><>F) = (<>F)"
215 by (auto simp add: dmd_def [try_rewrite] STL3 [try_rewrite])
217 lemmas dup_dmdE = DmdDmd [temp_unlift, THEN iffD2, elim_format]
218 lemmas dup_dmdD = DmdDmd [temp_unlift, THEN iffD1]
221 (* ------------------------ STL4 ------------------------------------------- *)
224 shows "|- []F --> []G"
226 apply (rule normalT [temp_use])
227 apply (rule assms [THEN necT, temp_use])
231 (* Unlifted version as an elimination rule *)
232 lemma STL4E: "[| sigma |= []F; |- F --> G |] ==> sigma |= []G"
233 by (erule (1) STL4 [temp_use])
235 lemma STL4_gen: "|- Init F --> Init G ==> |- []F --> []G"
237 apply (simp add: boxInitD)
240 lemma STL4E_gen: "[| sigma |= []F; |- Init F --> Init G |] ==> sigma |= []G"
241 by (erule (1) STL4_gen [temp_use])
243 (* see also STL4Edup below, which allows an auxiliary boxed formula:
249 (* The dual versions for <> *)
251 assumes prem: "|- F --> G"
252 shows "|- <>F --> <>G"
253 apply (unfold dmd_def)
254 apply (fastforce intro!: prem [temp_use] elim!: STL4E [temp_use])
257 lemma DmdImplE: "[| sigma |= <>F; |- F --> G |] ==> sigma |= <>G"
258 by (erule (1) DmdImpl [temp_use])
260 (* ------------------------ STL5 ------------------------------------------- *)
261 lemma STL5: "|- ([]F & []G) = ([](F & G))"
263 apply (subgoal_tac "sigma |= [] (G --> (F & G))")
264 apply (erule normalT [temp_use])
265 apply (fastforce elim!: STL4E [temp_use])+
268 (* rewrite rule to split conjunctions under boxes *)
269 lemmas split_box_conj = STL5 [temp_unlift, symmetric]
272 (* the corresponding elimination rule allows to combine boxes in the hypotheses
273 (NB: F and G must have the same type, i.e., both actions or temporals.)
274 Use "addSE2" etc. if you want to add this to a claset, otherwise it will loop!
277 assumes "sigma |= []F"
279 and "sigma |= [](F&G) ==> PROP R"
281 by (rule assms STL5 [temp_unlift, THEN iffD1] conjI)+
283 (* Instances of box_conjE for state predicates, actions, and temporals
284 in case the general rule is "too polymorphic".
286 lemmas box_conjE_temp = box_conjE [where 'a = behavior]
287 lemmas box_conjE_stp = box_conjE [where 'a = state]
288 lemmas box_conjE_act = box_conjE [where 'a = "state * state"]
290 (* Define a tactic that tries to merge all boxes in an antecedent. The definition is
291 a bit kludgy in order to simulate "double elim-resolution".
294 lemma box_thin: "[| sigma |= []F; PROP W |] ==> PROP W" .
297 fun merge_box_tac i =
298 REPEAT_DETERM (EVERY [etac @{thm box_conjE} i, atac i, etac @{thm box_thin} i])
300 fun merge_temp_box_tac ctxt i =
301 REPEAT_DETERM (EVERY [etac @{thm box_conjE_temp} i, atac i,
302 eres_inst_tac ctxt [(("'a", 0), "behavior")] @{thm box_thin} i])
304 fun merge_stp_box_tac ctxt i =
305 REPEAT_DETERM (EVERY [etac @{thm box_conjE_stp} i, atac i,
306 eres_inst_tac ctxt [(("'a", 0), "state")] @{thm box_thin} i])
308 fun merge_act_box_tac ctxt i =
309 REPEAT_DETERM (EVERY [etac @{thm box_conjE_act} i, atac i,
310 eres_inst_tac ctxt [(("'a", 0), "state * state")] @{thm box_thin} i])
313 method_setup merge_box = {* Scan.succeed (K (SIMPLE_METHOD' merge_box_tac)) *}
314 method_setup merge_temp_box = {* Scan.succeed (SIMPLE_METHOD' o merge_temp_box_tac) *}
315 method_setup merge_stp_box = {* Scan.succeed (SIMPLE_METHOD' o merge_stp_box_tac) *}
316 method_setup merge_act_box = {* Scan.succeed (SIMPLE_METHOD' o merge_act_box_tac) *}
318 (* rewrite rule to push universal quantification through box:
319 (sigma |= [](! x. F x)) = (! x. (sigma |= []F x))
321 lemmas all_box = allT [temp_unlift, symmetric]
323 lemma DmdOr: "|- (<>(F | G)) = (<>F | <>G)"
324 apply (auto simp add: dmd_def split_box_conj [try_rewrite])
325 apply (erule contrapos_np, merge_box, fastforce elim!: STL4E [temp_use])+
328 lemma exT: "|- (EX x. <>(F x)) = (<>(EX x. F x))"
329 by (auto simp: dmd_def Not_Rex [try_rewrite] all_box [try_rewrite])
331 lemmas ex_dmd = exT [temp_unlift, symmetric]
333 lemma STL4Edup: "!!sigma. [| sigma |= []A; sigma |= []F; |- F & []A --> G |] ==> sigma |= []G"
334 apply (erule dup_boxE)
341 "!!sigma. [| sigma |= <>F; sigma |= [](F --> G) |] ==> sigma |= <>G"
342 apply (unfold dmd_def)
346 apply (fastforce elim!: STL4E [temp_use])
350 assumes 1: "sigma |= []<>F"
351 and 2: "sigma |= []G"
352 and 3: "|- F & G --> H"
353 shows "sigma |= []<>H"
355 apply (erule_tac F = G in dup_boxE)
357 apply (fastforce elim!: STL4E [temp_use] DmdImpl2 [temp_use] intro!: 3 [temp_use])
360 (* ------------------------ STL6 ------------------------------------------- *)
361 (* Used in the proof of STL6, but useful in itself. *)
362 lemma BoxDmd: "|- []F & <>G --> <>([]F & G)"
363 apply (unfold dmd_def)
365 apply (erule dup_boxE)
367 apply (erule contrapos_np)
368 apply (fastforce elim!: STL4E [temp_use])
371 (* weaker than BoxDmd, but more polymorphic (and often just right) *)
372 lemma BoxDmd_simple: "|- []F & <>G --> <>(F & G)"
373 apply (unfold dmd_def)
376 apply (fastforce elim!: notE STL4E [temp_use])
379 lemma BoxDmd2_simple: "|- []F & <>G --> <>(G & F)"
380 apply (unfold dmd_def)
383 apply (fastforce elim!: notE STL4E [temp_use])
387 assumes 1: "sigma |= []A"
388 and 2: "sigma |= <>F"
389 and 3: "|- []A & F --> G"
391 apply (rule 2 [THEN 1 [THEN BoxDmd [temp_use]], THEN DmdImplE])
395 lemma STL6: "|- <>[]F & <>[]G --> <>[](F & G)"
396 apply (auto simp: STL5 [temp_rewrite, symmetric])
397 apply (drule linT [temp_use])
399 apply (erule thin_rl)
400 apply (rule DmdDmd [temp_unlift, THEN iffD1])
402 apply (erule DmdImplE)
404 apply (erule DmdImplE)
406 apply (drule BoxDmd [temp_use])
408 apply (erule thin_rl)
409 apply (fastforce elim!: DmdImplE [temp_use])
413 (* ------------------------ True / False ----------------------------------------- *)
414 section "Simplification of constants"
416 lemma BoxConst: "|- ([]#P) = #P"
419 apply (auto intro!: necT [temp_use] dest: STL2_gen [temp_use] simp: Init_simps)
422 lemma DmdConst: "|- (<>#P) = #P"
423 apply (unfold dmd_def)
425 apply (simp_all add: BoxConst [try_rewrite])
428 lemmas temp_simps [temp_rewrite, simp] = BoxConst DmdConst
431 (* ------------------------ Further rewrites ----------------------------------------- *)
432 section "Further rewrites"
434 lemma NotBox: "|- (~[]F) = (<>~F)"
435 by (simp add: dmd_def)
437 lemma NotDmd: "|- (~<>F) = ([]~F)"
438 by (simp add: dmd_def)
440 (* These are not declared by default, because they could be harmful,
441 e.g. []F & ~[]F becomes []F & <>~F !! *)
442 lemmas more_temp_simps1 =
443 STL3 [temp_rewrite] DmdDmd [temp_rewrite] NotBox [temp_rewrite] NotDmd [temp_rewrite]
444 NotBox [temp_unlift, THEN eq_reflection]
445 NotDmd [temp_unlift, THEN eq_reflection]
447 lemma BoxDmdBox: "|- ([]<>[]F) = (<>[]F)"
448 apply (auto dest!: STL2 [temp_use])
450 apply (subgoal_tac "sigma |= <>[][]F & <>[]~[]F")
451 apply (erule thin_rl)
453 apply (drule STL6 [temp_use])
456 apply (simp_all add: more_temp_simps1)
459 lemma DmdBoxDmd: "|- (<>[]<>F) = ([]<>F)"
460 apply (unfold dmd_def)
461 apply (auto simp: BoxDmdBox [unfolded dmd_def, try_rewrite])
464 lemmas more_temp_simps2 = more_temp_simps1 BoxDmdBox [temp_rewrite] DmdBoxDmd [temp_rewrite]
467 (* ------------------------ Miscellaneous ----------------------------------- *)
469 lemma BoxOr: "!!sigma. [| sigma |= []F | []G |] ==> sigma |= [](F | G)"
470 by (fastforce elim!: STL4E [temp_use])
472 (* "persistently implies infinitely often" *)
473 lemma DBImplBD: "|- <>[]F --> []<>F"
476 apply (simp add: more_temp_simps2)
477 apply (drule STL6 [temp_use])
482 lemma BoxDmdDmdBox: "|- []<>F & <>[]G --> []<>(F & G)"
485 apply (unfold more_temp_simps2)
486 apply (drule STL6 [temp_use])
488 apply (subgoal_tac "sigma |= <>[]~F")
489 apply (force simp: dmd_def)
490 apply (fastforce elim: DmdImplE [temp_use] STL4E [temp_use])
494 (* ------------------------------------------------------------------------- *)
495 (*** TLA-specific theorems: primed formulas ***)
496 (* ------------------------------------------------------------------------- *)
499 (* ------------------------ TLA2 ------------------------------------------- *)
500 lemma STL2_pr: "|- []P --> Init P & Init P`"
501 by (fastforce intro!: STL2_gen [temp_use] primeI [temp_use])
503 (* Auxiliary lemma allows priming of boxed actions *)
504 lemma BoxPrime: "|- []P --> []($P & P$)"
506 apply (erule dup_boxE)
507 apply (unfold boxInit_act)
509 apply (auto simp: Init_simps dest!: STL2_pr [temp_use])
513 assumes "|- $P & P$ --> A"
514 shows "|- []P --> []A"
516 apply (drule BoxPrime [temp_use])
517 apply (auto simp: Init_stp_act_rev [try_rewrite] intro!: assms [temp_use]
518 elim!: STL4E [temp_use])
521 lemma TLA2E: "[| sigma |= []P; |- $P & P$ --> A |] ==> sigma |= []A"
522 by (erule (1) TLA2 [temp_use])
524 lemma DmdPrime: "|- (<>P`) --> (<>P)"
525 apply (unfold dmd_def)
526 apply (fastforce elim!: TLA2E [temp_use])
529 lemmas PrimeDmd = InitDmd_gen [temp_use, THEN DmdPrime [temp_use]]
531 (* ------------------------ INV1, stable --------------------------------------- *)
532 section "stable, invariant"
535 "[| sigma |= []H; sigma |= Init P; |- H --> (Init P & ~[]F --> Init(P`) & F) |]
537 apply (rule indT [temp_use])
538 apply (erule (2) STL4E)
541 lemma box_stp_act: "|- ([]$P) = ([]P)"
542 by (simp add: boxInit_act Init_simps)
544 lemmas box_stp_actI = box_stp_act [temp_use, THEN iffD2]
545 lemmas box_stp_actD = box_stp_act [temp_use, THEN iffD1]
547 lemmas more_temp_simps3 = box_stp_act [temp_rewrite] more_temp_simps2
550 "|- (Init P) --> (stable P) --> []P"
551 apply (unfold stable_def boxInit_stp boxInit_act)
553 apply (erule ind_rule)
554 apply (auto simp: Init_simps elim: ind_rule)
558 "!!P. |- $P & A --> P` ==> |- []A --> stable P"
559 apply (unfold stable_def)
560 apply (fastforce elim!: STL4E [temp_use])
563 lemma Stable: "[| sigma |= []A; |- $P & A --> P` |] ==> sigma |= stable P"
564 by (erule (1) StableT [temp_use])
566 (* Generalization of INV1 *)
567 lemma StableBox: "|- (stable P) --> [](Init P --> []P)"
568 apply (unfold stable_def)
570 apply (erule dup_boxE)
571 apply (force simp: stable_def elim: STL4E [temp_use] INV1 [temp_use])
574 lemma DmdStable: "|- (stable P) & <>P --> <>[]P"
576 apply (rule DmdImpl2)
578 apply (erule StableBox [temp_use])
579 apply (simp add: dmdInitD)
582 (* ---------------- (Semi-)automatic invariant tactics ---------------------- *)
585 (* inv_tac reduces goals of the form ... ==> sigma |= []P *)
590 TRY (merge_box_tac 1),
591 rtac (temp_use @{thm INV1}) 1, (* fail if the goal is not a box *)
592 TRYALL (etac @{thm Stable})]);
594 (* auto_inv_tac applies inv_tac and then tries to attack the subgoals
595 in simple cases it may be able to handle goals like |- MyProg --> []Inv.
596 In these simple cases the simplifier seems to be more useful than the
597 auto-tactic, which applies too much propositional logic and simplifies
600 fun auto_inv_tac ctxt =
603 (TRYALL (action_simp_tac
604 (simpset_of ctxt addsimps [@{thm Init_stp}, @{thm Init_act}]) [] [@{thm squareE}])));
607 method_setup invariant = {*
608 Method.sections Clasimp.clasimp_modifiers >> (K (SIMPLE_METHOD' o inv_tac))
611 method_setup auto_invariant = {*
612 Method.sections Clasimp.clasimp_modifiers >> (K (SIMPLE_METHOD' o auto_inv_tac))
615 lemma unless: "|- []($P --> P` | Q`) --> (stable P) | <>Q"
616 apply (unfold dmd_def)
617 apply (clarsimp dest!: BoxPrime [temp_use])
619 apply (erule contrapos_np)
620 apply (fastforce elim!: Stable [temp_use])
624 (* --------------------- Recursive expansions --------------------------------------- *)
625 section "recursive expansions"
627 (* Recursive expansions of [] and <> for state predicates *)
628 lemma BoxRec: "|- ([]P) = (Init P & []P`)"
629 apply (auto intro!: STL2_gen [temp_use])
630 apply (fastforce elim!: TLA2E [temp_use])
631 apply (auto simp: stable_def elim!: INV1 [temp_use] STL4E [temp_use])
634 lemma DmdRec: "|- (<>P) = (Init P | <>P`)"
635 apply (unfold dmd_def BoxRec [temp_rewrite])
636 apply (auto simp: Init_simps)
639 lemma DmdRec2: "!!sigma. [| sigma |= <>P; sigma |= []~P` |] ==> sigma |= Init P"
640 apply (force simp: DmdRec [temp_rewrite] dmd_def)
643 lemma InfinitePrime: "|- ([]<>P) = ([]<>P`)"
645 apply (rule classical)
646 apply (rule DBImplBD [temp_use])
647 apply (subgoal_tac "sigma |= <>[]P")
648 apply (fastforce elim!: DmdImplE [temp_use] TLA2E [temp_use])
649 apply (subgoal_tac "sigma |= <>[] (<>P & []~P`)")
650 apply (force simp: boxInit_stp [temp_use]
651 elim!: DmdImplE [temp_use] STL4E [temp_use] DmdRec2 [temp_use])
652 apply (force intro!: STL6 [temp_use] simp: more_temp_simps3)
653 apply (fastforce intro: DmdPrime [temp_use] elim!: STL4E [temp_use])
656 lemma InfiniteEnsures:
657 "[| sigma |= []N; sigma |= []<>A; |- A & N --> P` |] ==> sigma |= []<>P"
658 apply (unfold InfinitePrime [temp_rewrite])
663 (* ------------------------ fairness ------------------------------------------- *)
666 (* alternative definitions of fairness *)
667 lemma WF_alt: "|- WF(A)_v = ([]<>~Enabled(<A>_v) | []<><A>_v)"
668 apply (unfold WF_def dmd_def)
672 lemma SF_alt: "|- SF(A)_v = (<>[]~Enabled(<A>_v) | []<><A>_v)"
673 apply (unfold SF_def dmd_def)
677 (* theorems to "box" fairness conditions *)
678 lemma BoxWFI: "|- WF(A)_v --> []WF(A)_v"
679 by (auto simp: WF_alt [try_rewrite] more_temp_simps3 intro!: BoxOr [temp_use])
681 lemma WF_Box: "|- ([]WF(A)_v) = WF(A)_v"
682 by (fastforce intro!: BoxWFI [temp_use] dest!: STL2 [temp_use])
684 lemma BoxSFI: "|- SF(A)_v --> []SF(A)_v"
685 by (auto simp: SF_alt [try_rewrite] more_temp_simps3 intro!: BoxOr [temp_use])
687 lemma SF_Box: "|- ([]SF(A)_v) = SF(A)_v"
688 by (fastforce intro!: BoxSFI [temp_use] dest!: STL2 [temp_use])
690 lemmas more_temp_simps = more_temp_simps3 WF_Box [temp_rewrite] SF_Box [temp_rewrite]
692 lemma SFImplWF: "|- SF(A)_v --> WF(A)_v"
693 apply (unfold SF_def WF_def)
694 apply (fastforce dest!: DBImplBD [temp_use])
697 (* A tactic that "boxes" all fairness conditions. Apply more_temp_simps to "unbox". *)
699 val box_fair_tac = SELECT_GOAL (REPEAT (dresolve_tac [@{thm BoxWFI}, @{thm BoxSFI}] 1))
703 (* ------------------------------ leads-to ------------------------------ *)
707 lemma leadsto_init: "|- (Init F) & (F ~> G) --> <>G"
708 apply (unfold leadsto_def)
709 apply (auto dest!: STL2 [temp_use])
712 (* |- F & (F ~> G) --> <>G *)
713 lemmas leadsto_init_temp = leadsto_init [where 'a = behavior, unfolded Init_simps]
715 lemma streett_leadsto: "|- ([]<>Init F --> []<>G) = (<>(F ~> G))"
716 apply (unfold leadsto_def)
718 apply (simp add: more_temp_simps)
719 apply (fastforce elim!: DmdImplE [temp_use] STL4E [temp_use])
720 apply (fastforce intro!: InitDmd [temp_use] elim!: STL4E [temp_use])
721 apply (subgoal_tac "sigma |= []<><>G")
722 apply (simp add: more_temp_simps)
723 apply (drule BoxDmdDmdBox [temp_use])
725 apply (fastforce elim!: DmdImplE [temp_use] STL4E [temp_use])
728 lemma leadsto_infinite: "|- []<>F & (F ~> G) --> []<>G"
730 apply (erule InitDmd [temp_use, THEN streett_leadsto [temp_unlift, THEN iffD2, THEN mp]])
731 apply (simp add: dmdInitD)
734 (* In particular, strong fairness is a Streett condition. The following
735 rules are sometimes easier to use than WF2 or SF2 below.
737 lemma leadsto_SF: "|- (Enabled(<A>_v) ~> <A>_v) --> SF(A)_v"
738 apply (unfold SF_def)
739 apply (clarsimp elim!: leadsto_infinite [temp_use])
742 lemma leadsto_WF: "|- (Enabled(<A>_v) ~> <A>_v) --> WF(A)_v"
743 by (clarsimp intro!: SFImplWF [temp_use] leadsto_SF [temp_use])
745 (* introduce an invariant into the proof of a leadsto assertion.
746 []I --> ((P ~> Q) = (P /\ I ~> Q))
748 lemma INV_leadsto: "|- []I & (P & I ~> Q) --> (P ~> Q)"
749 apply (unfold leadsto_def)
751 apply (erule STL4Edup)
753 apply (auto simp: Init_simps dest!: STL2_gen [temp_use])
756 lemma leadsto_classical: "|- (Init F & []~G ~> G) --> (F ~> G)"
757 apply (unfold leadsto_def dmd_def)
758 apply (force simp: Init_simps elim!: STL4E [temp_use])
761 lemma leadsto_false: "|- (F ~> #False) = ([]~F)"
762 apply (unfold leadsto_def)
763 apply (simp add: boxNotInitD)
766 lemma leadsto_exists: "|- ((EX x. F x) ~> G) = (ALL x. (F x ~> G))"
767 apply (unfold leadsto_def)
768 apply (auto simp: allT [try_rewrite] Init_simps elim!: STL4E [temp_use])
771 (* basic leadsto properties, cf. Unity *)
773 lemma ImplLeadsto_gen: "|- [](Init F --> Init G) --> (F ~> G)"
774 apply (unfold leadsto_def)
775 apply (auto intro!: InitDmd_gen [temp_use]
776 elim!: STL4E_gen [temp_use] simp: Init_simps)
780 ImplLeadsto_gen [where 'a = behavior and 'b = behavior, unfolded Init_simps]
782 lemma ImplLeadsto_simple: "!!F G. |- F --> G ==> |- F ~> G"
783 by (auto simp: Init_def intro!: ImplLeadsto_gen [temp_use] necT [temp_use])
785 lemma EnsuresLeadsto:
786 assumes "|- A & $P --> Q`"
787 shows "|- []A --> (P ~> Q)"
788 apply (unfold leadsto_def)
789 apply (clarsimp elim!: INV_leadsto [temp_use])
790 apply (erule STL4E_gen)
791 apply (auto simp: Init_defs intro!: PrimeDmd [temp_use] assms [temp_use])
794 lemma EnsuresLeadsto2: "|- []($P --> Q`) --> (P ~> Q)"
795 apply (unfold leadsto_def)
797 apply (erule STL4E_gen)
798 apply (auto simp: Init_simps intro!: PrimeDmd [temp_use])
802 assumes 1: "|- $P & N --> P` | Q`"
803 and 2: "|- ($P & N) & A --> Q`"
804 shows "|- []N & []([]P --> <>A) --> (P ~> Q)"
805 apply (unfold leadsto_def)
807 apply (erule STL4Edup)
810 apply (subgoal_tac "sigmaa |= [] ($P --> P` | Q`) ")
811 apply (drule unless [temp_use])
812 apply (clarsimp dest!: INV1 [temp_use])
813 apply (rule 2 [THEN DmdImpl, temp_use, THEN DmdPrime [temp_use]])
814 apply (force intro!: BoxDmd_simple [temp_use]
815 simp: split_box_conj [try_rewrite] box_stp_act [try_rewrite])
816 apply (force elim: STL4E [temp_use] dest: 1 [temp_use])
819 lemma ensures_simple:
820 "[| |- $P & N --> P` | Q`;
821 |- ($P & N) & A --> Q`
822 |] ==> |- []N & []<>A --> (P ~> Q)"
824 apply (erule (2) ensures [temp_use])
825 apply (force elim!: STL4E [temp_use])
828 lemma EnsuresInfinite:
829 "[| sigma |= []<>P; sigma |= []A; |- A & $P --> Q` |] ==> sigma |= []<>Q"
830 apply (erule leadsto_infinite [temp_use])
831 apply (erule EnsuresLeadsto [temp_use])
836 (*** Gronning's lattice rules (taken from TLP) ***)
837 section "Lattice rules"
839 lemma LatticeReflexivity: "|- F ~> F"
840 apply (unfold leadsto_def)
841 apply (rule necT InitDmd_gen)+
844 lemma LatticeTransitivity: "|- (G ~> H) & (F ~> G) --> (F ~> H)"
845 apply (unfold leadsto_def)
847 apply (erule dup_boxE) (* [][] (Init G --> H) *)
849 apply (clarsimp elim!: STL4E [temp_use])
850 apply (rule dup_dmdD)
851 apply (subgoal_tac "sigmaa |= <>Init G")
852 apply (erule DmdImpl2)
854 apply (simp add: dmdInitD)
857 lemma LatticeDisjunctionElim1: "|- (F | G ~> H) --> (F ~> H)"
858 apply (unfold leadsto_def)
859 apply (auto simp: Init_simps elim!: STL4E [temp_use])
862 lemma LatticeDisjunctionElim2: "|- (F | G ~> H) --> (G ~> H)"
863 apply (unfold leadsto_def)
864 apply (auto simp: Init_simps elim!: STL4E [temp_use])
867 lemma LatticeDisjunctionIntro: "|- (F ~> H) & (G ~> H) --> (F | G ~> H)"
868 apply (unfold leadsto_def)
871 apply (auto simp: Init_simps elim!: STL4E [temp_use])
874 lemma LatticeDisjunction: "|- (F | G ~> H) = ((F ~> H) & (G ~> H))"
875 by (auto intro: LatticeDisjunctionIntro [temp_use]
876 LatticeDisjunctionElim1 [temp_use]
877 LatticeDisjunctionElim2 [temp_use])
879 lemma LatticeDiamond: "|- (A ~> B | C) & (B ~> D) & (C ~> D) --> (A ~> D)"
881 apply (subgoal_tac "sigma |= (B | C) ~> D")
882 apply (erule_tac G = "LIFT (B | C)" in LatticeTransitivity [temp_use])
883 apply (fastforce intro!: LatticeDisjunctionIntro [temp_use])+
886 lemma LatticeTriangle: "|- (A ~> D | B) & (B ~> D) --> (A ~> D)"
888 apply (subgoal_tac "sigma |= (D | B) ~> D")
889 apply (erule_tac G = "LIFT (D | B)" in LatticeTransitivity [temp_use])
891 apply (auto intro: LatticeDisjunctionIntro [temp_use] LatticeReflexivity [temp_use])
894 lemma LatticeTriangle2: "|- (A ~> B | D) & (B ~> D) --> (A ~> D)"
896 apply (subgoal_tac "sigma |= B | D ~> D")
897 apply (erule_tac G = "LIFT (B | D)" in LatticeTransitivity [temp_use])
899 apply (auto intro: LatticeDisjunctionIntro [temp_use] LatticeReflexivity [temp_use])
902 (*** Lamport's fairness rules ***)
903 section "Fairness rules"
906 "[| |- $P & N --> P` | Q`;
907 |- ($P & N) & <A>_v --> Q`;
908 |- $P & N --> $(Enabled(<A>_v)) |]
909 ==> |- []N & WF(A)_v --> (P ~> Q)"
910 apply (clarsimp dest!: BoxWFI [temp_use])
911 apply (erule (2) ensures [temp_use])
912 apply (erule (1) STL4Edup)
913 apply (clarsimp simp: WF_def)
914 apply (rule STL2 [temp_use])
915 apply (clarsimp elim!: mp intro!: InitDmd [temp_use])
916 apply (erule STL4 [temp_use, THEN box_stp_actD [temp_use]])
917 apply (simp add: split_box_conj box_stp_actI)
920 (* Sometimes easier to use; designed for action B rather than state predicate Q *)
922 assumes 1: "|- N & $P --> $Enabled (<A>_v)"
923 and 2: "|- N & <A>_v --> B"
924 and 3: "|- [](N & [~A]_v) --> stable P"
925 shows "|- []N & WF(A)_v --> (P ~> B)"
926 apply (unfold leadsto_def)
927 apply (clarsimp dest!: BoxWFI [temp_use])
928 apply (erule (1) STL4Edup)
930 apply (rule 2 [THEN DmdImpl, temp_use])
931 apply (rule BoxDmd_simple [temp_use])
933 apply (rule classical)
934 apply (rule STL2 [temp_use])
935 apply (clarsimp simp: WF_def elim!: mp intro!: InitDmd [temp_use])
936 apply (rule 1 [THEN STL4, temp_use, THEN box_stp_actD])
937 apply (simp (no_asm_simp) add: split_box_conj [try_rewrite] box_stp_act [try_rewrite])
938 apply (erule INV1 [temp_use])
939 apply (rule 3 [temp_use])
940 apply (simp add: split_box_conj [try_rewrite] NotDmd [temp_use] not_angle [try_rewrite])
944 "[| |- $P & N --> P` | Q`;
945 |- ($P & N) & <A>_v --> Q`;
946 |- []P & []N & []F --> <>Enabled(<A>_v) |]
947 ==> |- []N & SF(A)_v & []F --> (P ~> Q)"
948 apply (clarsimp dest!: BoxSFI [temp_use])
949 apply (erule (2) ensures [temp_use])
950 apply (erule_tac F = F in dup_boxE)
952 apply (erule STL4Edup)
954 apply (clarsimp simp: SF_def)
955 apply (rule STL2 [temp_use])
957 apply (erule STL4 [temp_use])
958 apply (simp add: split_box_conj [try_rewrite] STL3 [try_rewrite])
962 assumes 1: "|- N & <B>_f --> <M>_g"
963 and 2: "|- $P & P` & <N & A>_f --> B"
964 and 3: "|- P & Enabled(<M>_g) --> Enabled(<A>_f)"
965 and 4: "|- [](N & [~B]_f) & WF(A)_f & []F & <>[]Enabled(<M>_g) --> <>[]P"
966 shows "|- []N & WF(A)_f & []F --> WF(M)_g"
967 apply (clarsimp dest!: BoxWFI [temp_use] BoxDmdBox [temp_use, THEN iffD2]
968 simp: WF_def [where A = M])
969 apply (erule_tac F = F in dup_boxE)
971 apply (erule STL4Edup)
973 apply (clarsimp intro!: BoxDmd_simple [temp_use, THEN 1 [THEN DmdImpl, temp_use]])
974 apply (rule classical)
975 apply (subgoal_tac "sigmaa |= <> (($P & P` & N) & <A>_f)")
976 apply (force simp: angle_def intro!: 2 [temp_use] elim!: DmdImplE [temp_use])
977 apply (rule BoxDmd_simple [THEN DmdImpl, unfolded DmdDmd [temp_rewrite], temp_use])
978 apply (simp add: NotDmd [temp_use] not_angle [try_rewrite])
980 apply (frule 4 [temp_use])
982 apply (drule STL6 [temp_use])
984 apply (erule_tac V = "sigmaa |= <>[]P" in thin_rl)
985 apply (erule_tac V = "sigmaa |= []F" in thin_rl)
986 apply (drule BoxWFI [temp_use])
987 apply (erule_tac F = "ACT N & [~B]_f" in dup_boxE)
989 apply (erule DmdImpldup)
991 apply (auto simp: split_box_conj [try_rewrite] STL3 [try_rewrite]
992 WF_Box [try_rewrite] box_stp_act [try_rewrite])
993 apply (force elim!: TLA2E [where P = P, temp_use])
994 apply (rule STL2 [temp_use])
995 apply (force simp: WF_def split_box_conj [try_rewrite]
996 elim!: mp intro!: InitDmd [temp_use] 3 [THEN STL4, temp_use])
1000 assumes 1: "|- N & <B>_f --> <M>_g"
1001 and 2: "|- $P & P` & <N & A>_f --> B"
1002 and 3: "|- P & Enabled(<M>_g) --> Enabled(<A>_f)"
1003 and 4: "|- [](N & [~B]_f) & SF(A)_f & []F & []<>Enabled(<M>_g) --> <>[]P"
1004 shows "|- []N & SF(A)_f & []F --> SF(M)_g"
1005 apply (clarsimp dest!: BoxSFI [temp_use] simp: 2 [try_rewrite] SF_def [where A = M])
1006 apply (erule_tac F = F in dup_boxE)
1007 apply (erule_tac F = "TEMP <>Enabled (<M>_g) " in dup_boxE)
1008 apply merge_temp_box
1009 apply (erule STL4Edup)
1011 apply (clarsimp intro!: BoxDmd_simple [temp_use, THEN 1 [THEN DmdImpl, temp_use]])
1012 apply (rule classical)
1013 apply (subgoal_tac "sigmaa |= <> (($P & P` & N) & <A>_f)")
1014 apply (force simp: angle_def intro!: 2 [temp_use] elim!: DmdImplE [temp_use])
1015 apply (rule BoxDmd_simple [THEN DmdImpl, unfolded DmdDmd [temp_rewrite], temp_use])
1016 apply (simp add: NotDmd [temp_use] not_angle [try_rewrite])
1018 apply (frule 4 [temp_use])
1020 apply (erule_tac V = "sigmaa |= []F" in thin_rl)
1021 apply (drule BoxSFI [temp_use])
1022 apply (erule_tac F = "TEMP <>Enabled (<M>_g)" in dup_boxE)
1023 apply (erule_tac F = "ACT N & [~B]_f" in dup_boxE)
1024 apply merge_temp_box
1025 apply (erule DmdImpldup)
1027 apply (auto simp: split_box_conj [try_rewrite] STL3 [try_rewrite]
1028 SF_Box [try_rewrite] box_stp_act [try_rewrite])
1029 apply (force elim!: TLA2E [where P = P, temp_use])
1030 apply (rule STL2 [temp_use])
1031 apply (force simp: SF_def split_box_conj [try_rewrite]
1032 elim!: mp InfImpl [temp_use] intro!: 3 [temp_use])
1035 (* ------------------------------------------------------------------------- *)
1036 (*** Liveness proofs by well-founded orderings ***)
1037 (* ------------------------------------------------------------------------- *)
1038 section "Well-founded orderings"
1042 and 2: "!!x. sigma |= F x ~> (G | (EX y. #((y,x):r) & F y)) "
1043 shows "sigma |= F x ~> G"
1044 apply (rule 1 [THEN wf_induct])
1045 apply (rule LatticeTriangle [temp_use])
1047 apply (auto simp: leadsto_exists [try_rewrite])
1048 apply (case_tac "(y,x) :r")
1050 apply (force simp: leadsto_def Init_simps intro!: necT [temp_use])
1053 (* If r is well-founded, state function v cannot decrease forever *)
1054 lemma wf_not_box_decrease: "!!r. wf r ==> |- [][ (v`, $v) : #r ]_v --> <>[][#False]_v"
1057 apply (subgoal_tac "sigma |= (EX x. v=#x) ~> #False")
1058 apply (drule leadsto_false [temp_use, THEN iffD1, THEN STL2_gen [temp_use]])
1059 apply (force simp: Init_defs)
1060 apply (clarsimp simp: leadsto_exists [try_rewrite] not_square [try_rewrite] more_temp_simps)
1061 apply (erule wf_leadsto)
1062 apply (rule ensures_simple [temp_use])
1063 apply (auto simp: square_def angle_def)
1066 (* "wf r ==> |- <>[][ (v`, $v) : #r ]_v --> <>[][#False]_v" *)
1067 lemmas wf_not_dmd_box_decrease =
1068 wf_not_box_decrease [THEN DmdImpl, unfolded more_temp_simps]
1070 (* If there are infinitely many steps where v decreases, then there
1071 have to be infinitely many non-stuttering steps where v doesn't decrease.
1073 lemma wf_box_dmd_decrease:
1075 shows "|- []<>((v`, $v) : #r) --> []<><(v`, $v) ~: #r>_v"
1078 apply (simp add: not_angle [try_rewrite] more_temp_simps)
1079 apply (drule 1 [THEN wf_not_dmd_box_decrease [temp_use]])
1080 apply (drule BoxDmdDmdBox [temp_use])
1082 apply (subgoal_tac "sigma |= []<> ((#False) ::action)")
1085 apply (rule DmdImpl)
1086 apply (force intro: 1 [THEN wf_irrefl, temp_use])
1089 (* In particular, for natural numbers, if n decreases infinitely often
1090 then it has to increase infinitely often.
1092 lemma nat_box_dmd_decrease: "!!n::nat stfun. |- []<>(n` < $n) --> []<>($n < n`)"
1094 apply (subgoal_tac "sigma |= []<><~ ((n`,$n) : #less_than) >_n")
1095 apply (erule thin_rl)
1097 apply (rule DmdImpl)
1098 apply (clarsimp simp: angle_def [try_rewrite])
1099 apply (rule wf_box_dmd_decrease [temp_use])
1100 apply (auto elim!: STL4E [temp_use] DmdImplE [temp_use])
1104 (* ------------------------------------------------------------------------- *)
1105 (*** Flexible quantification over state variables ***)
1106 (* ------------------------------------------------------------------------- *)
1107 section "Flexible quantification"
1110 assumes 1: "basevars vs"
1111 and 2: "(!!x. basevars (x,vs) ==> sigma |= F x)"
1112 shows "sigma |= (AALL x. F x)"
1113 by (auto simp: aall_def elim!: eexE [temp_use] intro!: 1 dest!: 2 [temp_use])
1115 lemma aallE: "|- (AALL x. F x) --> F x"
1116 apply (unfold aall_def)
1118 apply (erule contrapos_np)
1119 apply (force intro!: eexI [temp_use])
1122 (* monotonicity of quantification *)
1124 assumes 1: "sigma |= EEX x. F x"
1125 and 2: "!!x. sigma |= F x --> G x"
1126 shows "sigma |= EEX x. G x"
1127 apply (rule unit_base [THEN 1 [THEN eexE]])
1128 apply (rule eexI [temp_use])
1129 apply (erule 2 [unfolded intensional_rews, THEN mp])
1133 assumes 1: "sigma |= AALL x. F(x)"
1134 and 2: "!!x. sigma |= F(x) --> G(x)"
1135 shows "sigma |= AALL x. G(x)"
1136 apply (rule unit_base [THEN aallI])
1137 apply (rule 2 [unfolded intensional_rews, THEN mp])
1138 apply (rule 1 [THEN aallE [temp_use]])
1141 (* Derived history introduction rule *)
1143 assumes 1: "sigma |= Init I"
1144 and 2: "sigma |= []N"
1145 and 3: "basevars vs"
1146 and 4: "!!h. basevars(h,vs) ==> |- I & h = ha --> HI h"
1147 and 5: "!!h s t. [| basevars(h,vs); N (s,t); h t = hb (h s) (s,t) |] ==> HN h (s,t)"
1148 shows "sigma |= EEX h. Init (HI h) & [](HN h)"
1149 apply (rule history [temp_use, THEN eexE])
1151 apply (rule eexI [temp_use])
1157 apply (force elim!: STL4E [temp_use] 5 [temp_use])
1159 apply (force simp: Init_defs elim!: 4 [temp_use])
1162 (* ----------------------------------------------------------------------
1163 example of a history variable: existence of a clock
1166 lemma "|- EEX h. Init(h = #True) & [](h` = (~$h))"
1168 apply (rule historyI)
1169 apply (force simp: Init_defs intro!: unit_base [temp_use] necT [temp_use])+