src/HOL/TLA/TLA.thy
author wenzelm
Wed May 23 16:53:12 2012 +0200 (2012-05-23)
changeset 47968 3119ad2b5ad3
parent 45605 a89b4bc311a5
child 51668 5e1108291c7f
permissions -rw-r--r--
eliminated old 'axioms';
     1 (*  Title:      HOL/TLA/TLA.thy
     2     Author:     Stephan Merz
     3     Copyright:  1998 University of Munich
     4 *)
     5 
     6 header {* The temporal level of TLA *}
     7 
     8 theory TLA
     9 imports Init
    10 begin
    11 
    12 consts
    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"
    20 
    21   (* Quantification over (flexible) state variables *)
    22   EEx        :: "('a stfun => temporal) => temporal"       (binder "Eex " 10)
    23   AAll       :: "('a stfun => temporal) => temporal"       (binder "Aall " 10)
    24 
    25   (** concrete syntax **)
    26 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)
    33 
    34   "_EEx"     :: "[idts, lift] => lift"                ("(3EEX _./ _)" [0,10] 10)
    35   "_AAll"    :: "[idts, lift] => lift"                ("(3AALL _./ _)" [0,10] 10)
    36 
    37 translations
    38   "_Box"      ==   "CONST Box"
    39   "_Dmd"      ==   "CONST Dmd"
    40   "_leadsto"  ==   "CONST leadsto"
    41   "_stable"   ==   "CONST Stable"
    42   "_WF"       ==   "CONST WF"
    43   "_SF"       ==   "CONST SF"
    44   "_EEx v A"  ==   "Eex v. A"
    45   "_AAll v A" ==   "Aall v. A"
    46 
    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"
    55 
    56 syntax (xsymbols)
    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)
    62 
    63 syntax (HTML output)
    64   "_EEx"     :: "[idts, lift] => lift"                ("(3\<exists>\<exists> _./ _)" [0,10] 10)
    65   "_AAll"    :: "[idts, lift] => lift"                ("(3\<forall>\<forall> _./ _)" [0,10] 10)
    66 
    67 axiomatization where
    68   (* Definitions of derived operators *)
    69   dmd_def:      "\<And>F. TEMP <>F  ==  TEMP ~[]~F"
    70 
    71 axiomatization where
    72   boxInit:      "\<And>F. TEMP []F  ==  TEMP []Init F" and
    73   leadsto_def:  "\<And>F G. TEMP F ~> G  ==  TEMP [](Init F --> <>G)" and
    74   stable_def:   "\<And>P. TEMP stable P  ==  TEMP []($P --> P$)" and
    75   WF_def:       "TEMP WF(A)_v  ==  TEMP <>[] Enabled(<A>_v) --> []<><A>_v" and
    76   SF_def:       "TEMP SF(A)_v  ==  TEMP []<> Enabled(<A>_v) --> []<><A>_v" and
    77   aall_def:     "TEMP (AALL x. F x)  ==  TEMP ~ (EEX x. ~ F x)"
    78 
    79 axiomatization where
    80 (* Base axioms for raw TLA. *)
    81   normalT:    "\<And>F G. |- [](F --> G) --> ([]F --> []G)" and    (* polymorphic *)
    82   reflT:      "\<And>F. |- []F --> F" and         (* F::temporal *)
    83   transT:     "\<And>F. |- []F --> [][]F" and     (* polymorphic *)
    84   linT:       "\<And>F G. |- <>F & <>G --> (<>(F & <>G)) | (<>(G & <>F))" and
    85   discT:      "\<And>F. |- [](F --> <>(~F & <>F)) --> (F --> []<>F)" and
    86   primeI:     "\<And>P. |- []P --> Init P`" and
    87   primeE:     "\<And>P F. |- [](Init P --> []F) --> Init P` --> (F --> []F)" and
    88   indT:       "\<And>P F. |- [](Init P & ~[]F --> Init P` & F) --> Init P --> []F" and
    89   allT:       "\<And>F. |- (ALL x. [](F x)) = ([](ALL x. F x))"
    90 
    91 axiomatization where
    92   necT:       "\<And>F. |- F ==> |- []F"      (* polymorphic *)
    93 
    94 axiomatization where
    95 (* Flexible quantification: refinement mappings, history variables *)
    96   eexI:       "|- F x --> (EEX x. F x)" and
    97   eexE:       "[| sigma |= (EEX x. F x); basevars vs;
    98                  (!!x. [| basevars (x, vs); sigma |= F x |] ==> (G sigma)::bool)
    99               |] ==> G sigma" and
   100   history:    "|- EEX h. Init(h = ha) & [](!x. $h = #x --> h` = hb x)"
   101 
   102 
   103 (* Specialize intensional introduction/elimination rules for temporal formulas *)
   104 
   105 lemma tempI: "(!!sigma. sigma |= (F::temporal)) ==> |- F"
   106   apply (rule intI)
   107   apply (erule meta_spec)
   108   done
   109 
   110 lemma tempD: "|- (F::temporal) ==> sigma |= F"
   111   by (erule intD)
   112 
   113 
   114 (* ======== Functions to "unlift" temporal theorems ====== *)
   115 
   116 ML {*
   117 (* The following functions are specialized versions of the corresponding
   118    functions defined in theory Intensional in that they introduce a
   119    "world" parameter of type "behavior".
   120 *)
   121 fun temp_unlift th =
   122   (rewrite_rule @{thms action_rews} (th RS @{thm tempD})) handle THM _ => action_unlift th;
   123 
   124 (* Turn  |- F = G  into meta-level rewrite rule  F == G *)
   125 val temp_rewrite = int_rewrite
   126 
   127 fun temp_use th =
   128   case (concl_of th) of
   129     Const _ $ (Const (@{const_name Intensional.Valid}, _) $ _) =>
   130             ((flatten (temp_unlift th)) handle THM _ => th)
   131   | _ => th;
   132 
   133 fun try_rewrite th = temp_rewrite th handle THM _ => temp_use th;
   134 *}
   135 
   136 attribute_setup temp_unlift = {* Scan.succeed (Thm.rule_attribute (K temp_unlift)) *}
   137 attribute_setup temp_rewrite = {* Scan.succeed (Thm.rule_attribute (K temp_rewrite)) *}
   138 attribute_setup temp_use = {* Scan.succeed (Thm.rule_attribute (K temp_use)) *}
   139 attribute_setup try_rewrite = {* Scan.succeed (Thm.rule_attribute (K try_rewrite)) *}
   140 
   141 
   142 (* Update classical reasoner---will be updated once more below! *)
   143 
   144 declare tempI [intro!]
   145 declare tempD [dest]
   146 
   147 (* Modify the functions that add rules to simpsets, classical sets,
   148    and clasimpsets in order to accept "lifted" theorems
   149 *)
   150 
   151 (* ------------------------------------------------------------------------- *)
   152 (***           "Simple temporal logic": only [] and <>                     ***)
   153 (* ------------------------------------------------------------------------- *)
   154 section "Simple temporal logic"
   155 
   156 (* []~F == []~Init F *)
   157 lemmas boxNotInit = boxInit [of "LIFT ~F", unfolded Init_simps] for F
   158 
   159 lemma dmdInit: "TEMP <>F == TEMP <> Init F"
   160   apply (unfold dmd_def)
   161   apply (unfold boxInit [of "LIFT ~F"])
   162   apply (simp (no_asm) add: Init_simps)
   163   done
   164 
   165 lemmas dmdNotInit = dmdInit [of "LIFT ~F", unfolded Init_simps] for F
   166 
   167 (* boxInit and dmdInit cannot be used as rewrites, because they loop.
   168    Non-looping instances for state predicates and actions are occasionally useful.
   169 *)
   170 lemmas boxInit_stp = boxInit [where 'a = state]
   171 lemmas boxInit_act = boxInit [where 'a = "state * state"]
   172 lemmas dmdInit_stp = dmdInit [where 'a = state]
   173 lemmas dmdInit_act = dmdInit [where 'a = "state * state"]
   174 
   175 (* The symmetric equations can be used to get rid of Init *)
   176 lemmas boxInitD = boxInit [symmetric]
   177 lemmas dmdInitD = dmdInit [symmetric]
   178 lemmas boxNotInitD = boxNotInit [symmetric]
   179 lemmas dmdNotInitD = dmdNotInit [symmetric]
   180 
   181 lemmas Init_simps = Init_simps boxInitD dmdInitD boxNotInitD dmdNotInitD
   182 
   183 (* ------------------------ STL2 ------------------------------------------- *)
   184 lemmas STL2 = reflT
   185 
   186 (* The "polymorphic" (generic) variant *)
   187 lemma STL2_gen: "|- []F --> Init F"
   188   apply (unfold boxInit [of F])
   189   apply (rule STL2)
   190   done
   191 
   192 (* see also STL2_pr below: "|- []P --> Init P & Init (P`)" *)
   193 
   194 
   195 (* Dual versions for <> *)
   196 lemma InitDmd: "|- F --> <> F"
   197   apply (unfold dmd_def)
   198   apply (auto dest!: STL2 [temp_use])
   199   done
   200 
   201 lemma InitDmd_gen: "|- Init F --> <>F"
   202   apply clarsimp
   203   apply (drule InitDmd [temp_use])
   204   apply (simp add: dmdInitD)
   205   done
   206 
   207 
   208 (* ------------------------ STL3 ------------------------------------------- *)
   209 lemma STL3: "|- ([][]F) = ([]F)"
   210   by (auto elim: transT [temp_use] STL2 [temp_use])
   211 
   212 (* corresponding elimination rule introduces double boxes:
   213    [| (sigma |= []F); (sigma |= [][]F) ==> PROP W |] ==> PROP W
   214 *)
   215 lemmas dup_boxE = STL3 [temp_unlift, THEN iffD2, elim_format]
   216 lemmas dup_boxD = STL3 [temp_unlift, THEN iffD1]
   217 
   218 (* dual versions for <> *)
   219 lemma DmdDmd: "|- (<><>F) = (<>F)"
   220   by (auto simp add: dmd_def [try_rewrite] STL3 [try_rewrite])
   221 
   222 lemmas dup_dmdE = DmdDmd [temp_unlift, THEN iffD2, elim_format]
   223 lemmas dup_dmdD = DmdDmd [temp_unlift, THEN iffD1]
   224 
   225 
   226 (* ------------------------ STL4 ------------------------------------------- *)
   227 lemma STL4:
   228   assumes "|- F --> G"
   229   shows "|- []F --> []G"
   230   apply clarsimp
   231   apply (rule normalT [temp_use])
   232    apply (rule assms [THEN necT, temp_use])
   233   apply assumption
   234   done
   235 
   236 (* Unlifted version as an elimination rule *)
   237 lemma STL4E: "[| sigma |= []F; |- F --> G |] ==> sigma |= []G"
   238   by (erule (1) STL4 [temp_use])
   239 
   240 lemma STL4_gen: "|- Init F --> Init G ==> |- []F --> []G"
   241   apply (drule STL4)
   242   apply (simp add: boxInitD)
   243   done
   244 
   245 lemma STL4E_gen: "[| sigma |= []F; |- Init F --> Init G |] ==> sigma |= []G"
   246   by (erule (1) STL4_gen [temp_use])
   247 
   248 (* see also STL4Edup below, which allows an auxiliary boxed formula:
   249        []A /\ F => G
   250      -----------------
   251      []A /\ []F => []G
   252 *)
   253 
   254 (* The dual versions for <> *)
   255 lemma DmdImpl:
   256   assumes prem: "|- F --> G"
   257   shows "|- <>F --> <>G"
   258   apply (unfold dmd_def)
   259   apply (fastforce intro!: prem [temp_use] elim!: STL4E [temp_use])
   260   done
   261 
   262 lemma DmdImplE: "[| sigma |= <>F; |- F --> G |] ==> sigma |= <>G"
   263   by (erule (1) DmdImpl [temp_use])
   264 
   265 (* ------------------------ STL5 ------------------------------------------- *)
   266 lemma STL5: "|- ([]F & []G) = ([](F & G))"
   267   apply auto
   268   apply (subgoal_tac "sigma |= [] (G --> (F & G))")
   269      apply (erule normalT [temp_use])
   270      apply (fastforce elim!: STL4E [temp_use])+
   271   done
   272 
   273 (* rewrite rule to split conjunctions under boxes *)
   274 lemmas split_box_conj = STL5 [temp_unlift, symmetric]
   275 
   276 
   277 (* the corresponding elimination rule allows to combine boxes in the hypotheses
   278    (NB: F and G must have the same type, i.e., both actions or temporals.)
   279    Use "addSE2" etc. if you want to add this to a claset, otherwise it will loop!
   280 *)
   281 lemma box_conjE:
   282   assumes "sigma |= []F"
   283      and "sigma |= []G"
   284   and "sigma |= [](F&G) ==> PROP R"
   285   shows "PROP R"
   286   by (rule assms STL5 [temp_unlift, THEN iffD1] conjI)+
   287 
   288 (* Instances of box_conjE for state predicates, actions, and temporals
   289    in case the general rule is "too polymorphic".
   290 *)
   291 lemmas box_conjE_temp = box_conjE [where 'a = behavior]
   292 lemmas box_conjE_stp = box_conjE [where 'a = state]
   293 lemmas box_conjE_act = box_conjE [where 'a = "state * state"]
   294 
   295 (* Define a tactic that tries to merge all boxes in an antecedent. The definition is
   296    a bit kludgy in order to simulate "double elim-resolution".
   297 *)
   298 
   299 lemma box_thin: "[| sigma |= []F; PROP W |] ==> PROP W" .
   300 
   301 ML {*
   302 fun merge_box_tac i =
   303    REPEAT_DETERM (EVERY [etac @{thm box_conjE} i, atac i, etac @{thm box_thin} i])
   304 
   305 fun merge_temp_box_tac ctxt i =
   306    REPEAT_DETERM (EVERY [etac @{thm box_conjE_temp} i, atac i,
   307                          eres_inst_tac ctxt [(("'a", 0), "behavior")] @{thm box_thin} i])
   308 
   309 fun merge_stp_box_tac ctxt i =
   310    REPEAT_DETERM (EVERY [etac @{thm box_conjE_stp} i, atac i,
   311                          eres_inst_tac ctxt [(("'a", 0), "state")] @{thm box_thin} i])
   312 
   313 fun merge_act_box_tac ctxt i =
   314    REPEAT_DETERM (EVERY [etac @{thm box_conjE_act} i, atac i,
   315                          eres_inst_tac ctxt [(("'a", 0), "state * state")] @{thm box_thin} i])
   316 *}
   317 
   318 method_setup merge_box = {* Scan.succeed (K (SIMPLE_METHOD' merge_box_tac)) *}
   319 method_setup merge_temp_box = {* Scan.succeed (SIMPLE_METHOD' o merge_temp_box_tac) *}
   320 method_setup merge_stp_box = {* Scan.succeed (SIMPLE_METHOD' o merge_stp_box_tac) *}
   321 method_setup merge_act_box = {* Scan.succeed (SIMPLE_METHOD' o merge_act_box_tac) *}
   322 
   323 (* rewrite rule to push universal quantification through box:
   324       (sigma |= [](! x. F x)) = (! x. (sigma |= []F x))
   325 *)
   326 lemmas all_box = allT [temp_unlift, symmetric]
   327 
   328 lemma DmdOr: "|- (<>(F | G)) = (<>F | <>G)"
   329   apply (auto simp add: dmd_def split_box_conj [try_rewrite])
   330   apply (erule contrapos_np, merge_box, fastforce elim!: STL4E [temp_use])+
   331   done
   332 
   333 lemma exT: "|- (EX x. <>(F x)) = (<>(EX x. F x))"
   334   by (auto simp: dmd_def Not_Rex [try_rewrite] all_box [try_rewrite])
   335 
   336 lemmas ex_dmd = exT [temp_unlift, symmetric]
   337 
   338 lemma STL4Edup: "!!sigma. [| sigma |= []A; sigma |= []F; |- F & []A --> G |] ==> sigma |= []G"
   339   apply (erule dup_boxE)
   340   apply merge_box
   341   apply (erule STL4E)
   342   apply assumption
   343   done
   344 
   345 lemma DmdImpl2: 
   346     "!!sigma. [| sigma |= <>F; sigma |= [](F --> G) |] ==> sigma |= <>G"
   347   apply (unfold dmd_def)
   348   apply auto
   349   apply (erule notE)
   350   apply merge_box
   351   apply (fastforce elim!: STL4E [temp_use])
   352   done
   353 
   354 lemma InfImpl:
   355   assumes 1: "sigma |= []<>F"
   356     and 2: "sigma |= []G"
   357     and 3: "|- F & G --> H"
   358   shows "sigma |= []<>H"
   359   apply (insert 1 2)
   360   apply (erule_tac F = G in dup_boxE)
   361   apply merge_box
   362   apply (fastforce elim!: STL4E [temp_use] DmdImpl2 [temp_use] intro!: 3 [temp_use])
   363   done
   364 
   365 (* ------------------------ STL6 ------------------------------------------- *)
   366 (* Used in the proof of STL6, but useful in itself. *)
   367 lemma BoxDmd: "|- []F & <>G --> <>([]F & G)"
   368   apply (unfold dmd_def)
   369   apply clarsimp
   370   apply (erule dup_boxE)
   371   apply merge_box
   372   apply (erule contrapos_np)
   373   apply (fastforce elim!: STL4E [temp_use])
   374   done
   375 
   376 (* weaker than BoxDmd, but more polymorphic (and often just right) *)
   377 lemma BoxDmd_simple: "|- []F & <>G --> <>(F & G)"
   378   apply (unfold dmd_def)
   379   apply clarsimp
   380   apply merge_box
   381   apply (fastforce elim!: notE STL4E [temp_use])
   382   done
   383 
   384 lemma BoxDmd2_simple: "|- []F & <>G --> <>(G & F)"
   385   apply (unfold dmd_def)
   386   apply clarsimp
   387   apply merge_box
   388   apply (fastforce elim!: notE STL4E [temp_use])
   389   done
   390 
   391 lemma DmdImpldup:
   392   assumes 1: "sigma |= []A"
   393     and 2: "sigma |= <>F"
   394     and 3: "|- []A & F --> G"
   395   shows "sigma |= <>G"
   396   apply (rule 2 [THEN 1 [THEN BoxDmd [temp_use]], THEN DmdImplE])
   397   apply (rule 3)
   398   done
   399 
   400 lemma STL6: "|- <>[]F & <>[]G --> <>[](F & G)"
   401   apply (auto simp: STL5 [temp_rewrite, symmetric])
   402   apply (drule linT [temp_use])
   403    apply assumption
   404   apply (erule thin_rl)
   405   apply (rule DmdDmd [temp_unlift, THEN iffD1])
   406   apply (erule disjE)
   407    apply (erule DmdImplE)
   408    apply (rule BoxDmd)
   409   apply (erule DmdImplE)
   410   apply auto
   411   apply (drule BoxDmd [temp_use])
   412    apply assumption
   413   apply (erule thin_rl)
   414   apply (fastforce elim!: DmdImplE [temp_use])
   415   done
   416 
   417 
   418 (* ------------------------ True / False ----------------------------------------- *)
   419 section "Simplification of constants"
   420 
   421 lemma BoxConst: "|- ([]#P) = #P"
   422   apply (rule tempI)
   423   apply (cases P)
   424    apply (auto intro!: necT [temp_use] dest: STL2_gen [temp_use] simp: Init_simps)
   425   done
   426 
   427 lemma DmdConst: "|- (<>#P) = #P"
   428   apply (unfold dmd_def)
   429   apply (cases P)
   430   apply (simp_all add: BoxConst [try_rewrite])
   431   done
   432 
   433 lemmas temp_simps [temp_rewrite, simp] = BoxConst DmdConst
   434 
   435 
   436 (* ------------------------ Further rewrites ----------------------------------------- *)
   437 section "Further rewrites"
   438 
   439 lemma NotBox: "|- (~[]F) = (<>~F)"
   440   by (simp add: dmd_def)
   441 
   442 lemma NotDmd: "|- (~<>F) = ([]~F)"
   443   by (simp add: dmd_def)
   444 
   445 (* These are not declared by default, because they could be harmful,
   446    e.g. []F & ~[]F becomes []F & <>~F !! *)
   447 lemmas more_temp_simps1 =
   448   STL3 [temp_rewrite] DmdDmd [temp_rewrite] NotBox [temp_rewrite] NotDmd [temp_rewrite]
   449   NotBox [temp_unlift, THEN eq_reflection]
   450   NotDmd [temp_unlift, THEN eq_reflection]
   451 
   452 lemma BoxDmdBox: "|- ([]<>[]F) = (<>[]F)"
   453   apply (auto dest!: STL2 [temp_use])
   454   apply (rule ccontr)
   455   apply (subgoal_tac "sigma |= <>[][]F & <>[]~[]F")
   456    apply (erule thin_rl)
   457    apply auto
   458     apply (drule STL6 [temp_use])
   459      apply assumption
   460     apply simp
   461    apply (simp_all add: more_temp_simps1)
   462   done
   463 
   464 lemma DmdBoxDmd: "|- (<>[]<>F) = ([]<>F)"
   465   apply (unfold dmd_def)
   466   apply (auto simp: BoxDmdBox [unfolded dmd_def, try_rewrite])
   467   done
   468 
   469 lemmas more_temp_simps2 = more_temp_simps1 BoxDmdBox [temp_rewrite] DmdBoxDmd [temp_rewrite]
   470 
   471 
   472 (* ------------------------ Miscellaneous ----------------------------------- *)
   473 
   474 lemma BoxOr: "!!sigma. [| sigma |= []F | []G |] ==> sigma |= [](F | G)"
   475   by (fastforce elim!: STL4E [temp_use])
   476 
   477 (* "persistently implies infinitely often" *)
   478 lemma DBImplBD: "|- <>[]F --> []<>F"
   479   apply clarsimp
   480   apply (rule ccontr)
   481   apply (simp add: more_temp_simps2)
   482   apply (drule STL6 [temp_use])
   483    apply assumption
   484   apply simp
   485   done
   486 
   487 lemma BoxDmdDmdBox: "|- []<>F & <>[]G --> []<>(F & G)"
   488   apply clarsimp
   489   apply (rule ccontr)
   490   apply (unfold more_temp_simps2)
   491   apply (drule STL6 [temp_use])
   492    apply assumption
   493   apply (subgoal_tac "sigma |= <>[]~F")
   494    apply (force simp: dmd_def)
   495   apply (fastforce elim: DmdImplE [temp_use] STL4E [temp_use])
   496   done
   497 
   498 
   499 (* ------------------------------------------------------------------------- *)
   500 (***          TLA-specific theorems: primed formulas                       ***)
   501 (* ------------------------------------------------------------------------- *)
   502 section "priming"
   503 
   504 (* ------------------------ TLA2 ------------------------------------------- *)
   505 lemma STL2_pr: "|- []P --> Init P & Init P`"
   506   by (fastforce intro!: STL2_gen [temp_use] primeI [temp_use])
   507 
   508 (* Auxiliary lemma allows priming of boxed actions *)
   509 lemma BoxPrime: "|- []P --> []($P & P$)"
   510   apply clarsimp
   511   apply (erule dup_boxE)
   512   apply (unfold boxInit_act)
   513   apply (erule STL4E)
   514   apply (auto simp: Init_simps dest!: STL2_pr [temp_use])
   515   done
   516 
   517 lemma TLA2:
   518   assumes "|- $P & P$ --> A"
   519   shows "|- []P --> []A"
   520   apply clarsimp
   521   apply (drule BoxPrime [temp_use])
   522   apply (auto simp: Init_stp_act_rev [try_rewrite] intro!: assms [temp_use]
   523     elim!: STL4E [temp_use])
   524   done
   525 
   526 lemma TLA2E: "[| sigma |= []P; |- $P & P$ --> A |] ==> sigma |= []A"
   527   by (erule (1) TLA2 [temp_use])
   528 
   529 lemma DmdPrime: "|- (<>P`) --> (<>P)"
   530   apply (unfold dmd_def)
   531   apply (fastforce elim!: TLA2E [temp_use])
   532   done
   533 
   534 lemmas PrimeDmd = InitDmd_gen [temp_use, THEN DmdPrime [temp_use]]
   535 
   536 (* ------------------------ INV1, stable --------------------------------------- *)
   537 section "stable, invariant"
   538 
   539 lemma ind_rule:
   540    "[| sigma |= []H; sigma |= Init P; |- H --> (Init P & ~[]F --> Init(P`) & F) |]  
   541     ==> sigma |= []F"
   542   apply (rule indT [temp_use])
   543    apply (erule (2) STL4E)
   544   done
   545 
   546 lemma box_stp_act: "|- ([]$P) = ([]P)"
   547   by (simp add: boxInit_act Init_simps)
   548 
   549 lemmas box_stp_actI = box_stp_act [temp_use, THEN iffD2]
   550 lemmas box_stp_actD = box_stp_act [temp_use, THEN iffD1]
   551 
   552 lemmas more_temp_simps3 = box_stp_act [temp_rewrite] more_temp_simps2
   553 
   554 lemma INV1: 
   555   "|- (Init P) --> (stable P) --> []P"
   556   apply (unfold stable_def boxInit_stp boxInit_act)
   557   apply clarsimp
   558   apply (erule ind_rule)
   559    apply (auto simp: Init_simps elim: ind_rule)
   560   done
   561 
   562 lemma StableT: 
   563     "!!P. |- $P & A --> P` ==> |- []A --> stable P"
   564   apply (unfold stable_def)
   565   apply (fastforce elim!: STL4E [temp_use])
   566   done
   567 
   568 lemma Stable: "[| sigma |= []A; |- $P & A --> P` |] ==> sigma |= stable P"
   569   by (erule (1) StableT [temp_use])
   570 
   571 (* Generalization of INV1 *)
   572 lemma StableBox: "|- (stable P) --> [](Init P --> []P)"
   573   apply (unfold stable_def)
   574   apply clarsimp
   575   apply (erule dup_boxE)
   576   apply (force simp: stable_def elim: STL4E [temp_use] INV1 [temp_use])
   577   done
   578 
   579 lemma DmdStable: "|- (stable P) & <>P --> <>[]P"
   580   apply clarsimp
   581   apply (rule DmdImpl2)
   582    prefer 2
   583    apply (erule StableBox [temp_use])
   584   apply (simp add: dmdInitD)
   585   done
   586 
   587 (* ---------------- (Semi-)automatic invariant tactics ---------------------- *)
   588 
   589 ML {*
   590 (* inv_tac reduces goals of the form ... ==> sigma |= []P *)
   591 fun inv_tac ctxt =
   592   SELECT_GOAL
   593     (EVERY
   594      [auto_tac ctxt,
   595       TRY (merge_box_tac 1),
   596       rtac (temp_use @{thm INV1}) 1, (* fail if the goal is not a box *)
   597       TRYALL (etac @{thm Stable})]);
   598 
   599 (* auto_inv_tac applies inv_tac and then tries to attack the subgoals
   600    in simple cases it may be able to handle goals like |- MyProg --> []Inv.
   601    In these simple cases the simplifier seems to be more useful than the
   602    auto-tactic, which applies too much propositional logic and simplifies
   603    too late.
   604 *)
   605 fun auto_inv_tac ctxt =
   606   SELECT_GOAL
   607     (inv_tac ctxt 1 THEN
   608       (TRYALL (action_simp_tac
   609         (simpset_of ctxt addsimps [@{thm Init_stp}, @{thm Init_act}]) [] [@{thm squareE}])));
   610 *}
   611 
   612 method_setup invariant = {*
   613   Method.sections Clasimp.clasimp_modifiers >> (K (SIMPLE_METHOD' o inv_tac))
   614 *}
   615 
   616 method_setup auto_invariant = {*
   617   Method.sections Clasimp.clasimp_modifiers >> (K (SIMPLE_METHOD' o auto_inv_tac))
   618 *}
   619 
   620 lemma unless: "|- []($P --> P` | Q`) --> (stable P) | <>Q"
   621   apply (unfold dmd_def)
   622   apply (clarsimp dest!: BoxPrime [temp_use])
   623   apply merge_box
   624   apply (erule contrapos_np)
   625   apply (fastforce elim!: Stable [temp_use])
   626   done
   627 
   628 
   629 (* --------------------- Recursive expansions --------------------------------------- *)
   630 section "recursive expansions"
   631 
   632 (* Recursive expansions of [] and <> for state predicates *)
   633 lemma BoxRec: "|- ([]P) = (Init P & []P`)"
   634   apply (auto intro!: STL2_gen [temp_use])
   635    apply (fastforce elim!: TLA2E [temp_use])
   636   apply (auto simp: stable_def elim!: INV1 [temp_use] STL4E [temp_use])
   637   done
   638 
   639 lemma DmdRec: "|- (<>P) = (Init P | <>P`)"
   640   apply (unfold dmd_def BoxRec [temp_rewrite])
   641   apply (auto simp: Init_simps)
   642   done
   643 
   644 lemma DmdRec2: "!!sigma. [| sigma |= <>P; sigma |= []~P` |] ==> sigma |= Init P"
   645   apply (force simp: DmdRec [temp_rewrite] dmd_def)
   646   done
   647 
   648 lemma InfinitePrime: "|- ([]<>P) = ([]<>P`)"
   649   apply auto
   650    apply (rule classical)
   651    apply (rule DBImplBD [temp_use])
   652    apply (subgoal_tac "sigma |= <>[]P")
   653     apply (fastforce elim!: DmdImplE [temp_use] TLA2E [temp_use])
   654    apply (subgoal_tac "sigma |= <>[] (<>P & []~P`)")
   655     apply (force simp: boxInit_stp [temp_use]
   656       elim!: DmdImplE [temp_use] STL4E [temp_use] DmdRec2 [temp_use])
   657    apply (force intro!: STL6 [temp_use] simp: more_temp_simps3)
   658   apply (fastforce intro: DmdPrime [temp_use] elim!: STL4E [temp_use])
   659   done
   660 
   661 lemma InfiniteEnsures:
   662   "[| sigma |= []N; sigma |= []<>A; |- A & N --> P` |] ==> sigma |= []<>P"
   663   apply (unfold InfinitePrime [temp_rewrite])
   664   apply (rule InfImpl)
   665     apply assumption+
   666   done
   667 
   668 (* ------------------------ fairness ------------------------------------------- *)
   669 section "fairness"
   670 
   671 (* alternative definitions of fairness *)
   672 lemma WF_alt: "|- WF(A)_v = ([]<>~Enabled(<A>_v) | []<><A>_v)"
   673   apply (unfold WF_def dmd_def)
   674   apply fastforce
   675   done
   676 
   677 lemma SF_alt: "|- SF(A)_v = (<>[]~Enabled(<A>_v) | []<><A>_v)"
   678   apply (unfold SF_def dmd_def)
   679   apply fastforce
   680   done
   681 
   682 (* theorems to "box" fairness conditions *)
   683 lemma BoxWFI: "|- WF(A)_v --> []WF(A)_v"
   684   by (auto simp: WF_alt [try_rewrite] more_temp_simps3 intro!: BoxOr [temp_use])
   685 
   686 lemma WF_Box: "|- ([]WF(A)_v) = WF(A)_v"
   687   by (fastforce intro!: BoxWFI [temp_use] dest!: STL2 [temp_use])
   688 
   689 lemma BoxSFI: "|- SF(A)_v --> []SF(A)_v"
   690   by (auto simp: SF_alt [try_rewrite] more_temp_simps3 intro!: BoxOr [temp_use])
   691 
   692 lemma SF_Box: "|- ([]SF(A)_v) = SF(A)_v"
   693   by (fastforce intro!: BoxSFI [temp_use] dest!: STL2 [temp_use])
   694 
   695 lemmas more_temp_simps = more_temp_simps3 WF_Box [temp_rewrite] SF_Box [temp_rewrite]
   696 
   697 lemma SFImplWF: "|- SF(A)_v --> WF(A)_v"
   698   apply (unfold SF_def WF_def)
   699   apply (fastforce dest!: DBImplBD [temp_use])
   700   done
   701 
   702 (* A tactic that "boxes" all fairness conditions. Apply more_temp_simps to "unbox". *)
   703 ML {*
   704 val box_fair_tac = SELECT_GOAL (REPEAT (dresolve_tac [@{thm BoxWFI}, @{thm BoxSFI}] 1))
   705 *}
   706 
   707 
   708 (* ------------------------------ leads-to ------------------------------ *)
   709 
   710 section "~>"
   711 
   712 lemma leadsto_init: "|- (Init F) & (F ~> G) --> <>G"
   713   apply (unfold leadsto_def)
   714   apply (auto dest!: STL2 [temp_use])
   715   done
   716 
   717 (* |- F & (F ~> G) --> <>G *)
   718 lemmas leadsto_init_temp = leadsto_init [where 'a = behavior, unfolded Init_simps]
   719 
   720 lemma streett_leadsto: "|- ([]<>Init F --> []<>G) = (<>(F ~> G))"
   721   apply (unfold leadsto_def)
   722   apply auto
   723     apply (simp add: more_temp_simps)
   724     apply (fastforce elim!: DmdImplE [temp_use] STL4E [temp_use])
   725    apply (fastforce intro!: InitDmd [temp_use] elim!: STL4E [temp_use])
   726   apply (subgoal_tac "sigma |= []<><>G")
   727    apply (simp add: more_temp_simps)
   728   apply (drule BoxDmdDmdBox [temp_use])
   729    apply assumption
   730   apply (fastforce elim!: DmdImplE [temp_use] STL4E [temp_use])
   731   done
   732 
   733 lemma leadsto_infinite: "|- []<>F & (F ~> G) --> []<>G"
   734   apply clarsimp
   735   apply (erule InitDmd [temp_use, THEN streett_leadsto [temp_unlift, THEN iffD2, THEN mp]])
   736   apply (simp add: dmdInitD)
   737   done
   738 
   739 (* In particular, strong fairness is a Streett condition. The following
   740    rules are sometimes easier to use than WF2 or SF2 below.
   741 *)
   742 lemma leadsto_SF: "|- (Enabled(<A>_v) ~> <A>_v) --> SF(A)_v"
   743   apply (unfold SF_def)
   744   apply (clarsimp elim!: leadsto_infinite [temp_use])
   745   done
   746 
   747 lemma leadsto_WF: "|- (Enabled(<A>_v) ~> <A>_v) --> WF(A)_v"
   748   by (clarsimp intro!: SFImplWF [temp_use] leadsto_SF [temp_use])
   749 
   750 (* introduce an invariant into the proof of a leadsto assertion.
   751    []I --> ((P ~> Q)  =  (P /\ I ~> Q))
   752 *)
   753 lemma INV_leadsto: "|- []I & (P & I ~> Q) --> (P ~> Q)"
   754   apply (unfold leadsto_def)
   755   apply clarsimp
   756   apply (erule STL4Edup)
   757    apply assumption
   758   apply (auto simp: Init_simps dest!: STL2_gen [temp_use])
   759   done
   760 
   761 lemma leadsto_classical: "|- (Init F & []~G ~> G) --> (F ~> G)"
   762   apply (unfold leadsto_def dmd_def)
   763   apply (force simp: Init_simps elim!: STL4E [temp_use])
   764   done
   765 
   766 lemma leadsto_false: "|- (F ~> #False) = ([]~F)"
   767   apply (unfold leadsto_def)
   768   apply (simp add: boxNotInitD)
   769   done
   770 
   771 lemma leadsto_exists: "|- ((EX x. F x) ~> G) = (ALL x. (F x ~> G))"
   772   apply (unfold leadsto_def)
   773   apply (auto simp: allT [try_rewrite] Init_simps elim!: STL4E [temp_use])
   774   done
   775 
   776 (* basic leadsto properties, cf. Unity *)
   777 
   778 lemma ImplLeadsto_gen: "|- [](Init F --> Init G) --> (F ~> G)"
   779   apply (unfold leadsto_def)
   780   apply (auto intro!: InitDmd_gen [temp_use]
   781     elim!: STL4E_gen [temp_use] simp: Init_simps)
   782   done
   783 
   784 lemmas ImplLeadsto =
   785   ImplLeadsto_gen [where 'a = behavior and 'b = behavior, unfolded Init_simps]
   786 
   787 lemma ImplLeadsto_simple: "!!F G. |- F --> G ==> |- F ~> G"
   788   by (auto simp: Init_def intro!: ImplLeadsto_gen [temp_use] necT [temp_use])
   789 
   790 lemma EnsuresLeadsto:
   791   assumes "|- A & $P --> Q`"
   792   shows "|- []A --> (P ~> Q)"
   793   apply (unfold leadsto_def)
   794   apply (clarsimp elim!: INV_leadsto [temp_use])
   795   apply (erule STL4E_gen)
   796   apply (auto simp: Init_defs intro!: PrimeDmd [temp_use] assms [temp_use])
   797   done
   798 
   799 lemma EnsuresLeadsto2: "|- []($P --> Q`) --> (P ~> Q)"
   800   apply (unfold leadsto_def)
   801   apply clarsimp
   802   apply (erule STL4E_gen)
   803   apply (auto simp: Init_simps intro!: PrimeDmd [temp_use])
   804   done
   805 
   806 lemma ensures:
   807   assumes 1: "|- $P & N --> P` | Q`"
   808     and 2: "|- ($P & N) & A --> Q`"
   809   shows "|- []N & []([]P --> <>A) --> (P ~> Q)"
   810   apply (unfold leadsto_def)
   811   apply clarsimp
   812   apply (erule STL4Edup)
   813    apply assumption
   814   apply clarsimp
   815   apply (subgoal_tac "sigmaa |= [] ($P --> P` | Q`) ")
   816    apply (drule unless [temp_use])
   817    apply (clarsimp dest!: INV1 [temp_use])
   818   apply (rule 2 [THEN DmdImpl, temp_use, THEN DmdPrime [temp_use]])
   819    apply (force intro!: BoxDmd_simple [temp_use]
   820      simp: split_box_conj [try_rewrite] box_stp_act [try_rewrite])
   821   apply (force elim: STL4E [temp_use] dest: 1 [temp_use])
   822   done
   823 
   824 lemma ensures_simple:
   825   "[| |- $P & N --> P` | Q`;  
   826       |- ($P & N) & A --> Q`  
   827    |] ==> |- []N & []<>A --> (P ~> Q)"
   828   apply clarsimp
   829   apply (erule (2) ensures [temp_use])
   830   apply (force elim!: STL4E [temp_use])
   831   done
   832 
   833 lemma EnsuresInfinite:
   834     "[| sigma |= []<>P; sigma |= []A; |- A & $P --> Q` |] ==> sigma |= []<>Q"
   835   apply (erule leadsto_infinite [temp_use])
   836   apply (erule EnsuresLeadsto [temp_use])
   837   apply assumption
   838   done
   839 
   840 
   841 (*** Gronning's lattice rules (taken from TLP) ***)
   842 section "Lattice rules"
   843 
   844 lemma LatticeReflexivity: "|- F ~> F"
   845   apply (unfold leadsto_def)
   846   apply (rule necT InitDmd_gen)+
   847   done
   848 
   849 lemma LatticeTransitivity: "|- (G ~> H) & (F ~> G) --> (F ~> H)"
   850   apply (unfold leadsto_def)
   851   apply clarsimp
   852   apply (erule dup_boxE) (* [][] (Init G --> H) *)
   853   apply merge_box
   854   apply (clarsimp elim!: STL4E [temp_use])
   855   apply (rule dup_dmdD)
   856   apply (subgoal_tac "sigmaa |= <>Init G")
   857    apply (erule DmdImpl2)
   858    apply assumption
   859   apply (simp add: dmdInitD)
   860   done
   861 
   862 lemma LatticeDisjunctionElim1: "|- (F | G ~> H) --> (F ~> H)"
   863   apply (unfold leadsto_def)
   864   apply (auto simp: Init_simps elim!: STL4E [temp_use])
   865   done
   866 
   867 lemma LatticeDisjunctionElim2: "|- (F | G ~> H) --> (G ~> H)"
   868   apply (unfold leadsto_def)
   869   apply (auto simp: Init_simps elim!: STL4E [temp_use])
   870   done
   871 
   872 lemma LatticeDisjunctionIntro: "|- (F ~> H) & (G ~> H) --> (F | G ~> H)"
   873   apply (unfold leadsto_def)
   874   apply clarsimp
   875   apply merge_box
   876   apply (auto simp: Init_simps elim!: STL4E [temp_use])
   877   done
   878 
   879 lemma LatticeDisjunction: "|- (F | G ~> H) = ((F ~> H) & (G ~> H))"
   880   by (auto intro: LatticeDisjunctionIntro [temp_use]
   881     LatticeDisjunctionElim1 [temp_use]
   882     LatticeDisjunctionElim2 [temp_use])
   883 
   884 lemma LatticeDiamond: "|- (A ~> B | C) & (B ~> D) & (C ~> D) --> (A ~> D)"
   885   apply clarsimp
   886   apply (subgoal_tac "sigma |= (B | C) ~> D")
   887   apply (erule_tac G = "LIFT (B | C)" in LatticeTransitivity [temp_use])
   888    apply (fastforce intro!: LatticeDisjunctionIntro [temp_use])+
   889   done
   890 
   891 lemma LatticeTriangle: "|- (A ~> D | B) & (B ~> D) --> (A ~> D)"
   892   apply clarsimp
   893   apply (subgoal_tac "sigma |= (D | B) ~> D")
   894    apply (erule_tac G = "LIFT (D | B)" in LatticeTransitivity [temp_use])
   895   apply assumption
   896   apply (auto intro: LatticeDisjunctionIntro [temp_use] LatticeReflexivity [temp_use])
   897   done
   898 
   899 lemma LatticeTriangle2: "|- (A ~> B | D) & (B ~> D) --> (A ~> D)"
   900   apply clarsimp
   901   apply (subgoal_tac "sigma |= B | D ~> D")
   902    apply (erule_tac G = "LIFT (B | D)" in LatticeTransitivity [temp_use])
   903    apply assumption
   904   apply (auto intro: LatticeDisjunctionIntro [temp_use] LatticeReflexivity [temp_use])
   905   done
   906 
   907 (*** Lamport's fairness rules ***)
   908 section "Fairness rules"
   909 
   910 lemma WF1:
   911   "[| |- $P & N  --> P` | Q`;    
   912       |- ($P & N) & <A>_v --> Q`;    
   913       |- $P & N --> $(Enabled(<A>_v)) |]    
   914   ==> |- []N & WF(A)_v --> (P ~> Q)"
   915   apply (clarsimp dest!: BoxWFI [temp_use])
   916   apply (erule (2) ensures [temp_use])
   917   apply (erule (1) STL4Edup)
   918   apply (clarsimp simp: WF_def)
   919   apply (rule STL2 [temp_use])
   920   apply (clarsimp elim!: mp intro!: InitDmd [temp_use])
   921   apply (erule STL4 [temp_use, THEN box_stp_actD [temp_use]])
   922   apply (simp add: split_box_conj box_stp_actI)
   923   done
   924 
   925 (* Sometimes easier to use; designed for action B rather than state predicate Q *)
   926 lemma WF_leadsto:
   927   assumes 1: "|- N & $P --> $Enabled (<A>_v)"
   928     and 2: "|- N & <A>_v --> B"
   929     and 3: "|- [](N & [~A]_v) --> stable P"
   930   shows "|- []N & WF(A)_v --> (P ~> B)"
   931   apply (unfold leadsto_def)
   932   apply (clarsimp dest!: BoxWFI [temp_use])
   933   apply (erule (1) STL4Edup)
   934   apply clarsimp
   935   apply (rule 2 [THEN DmdImpl, temp_use])
   936   apply (rule BoxDmd_simple [temp_use])
   937    apply assumption
   938   apply (rule classical)
   939   apply (rule STL2 [temp_use])
   940   apply (clarsimp simp: WF_def elim!: mp intro!: InitDmd [temp_use])
   941   apply (rule 1 [THEN STL4, temp_use, THEN box_stp_actD])
   942   apply (simp (no_asm_simp) add: split_box_conj [try_rewrite] box_stp_act [try_rewrite])
   943   apply (erule INV1 [temp_use])
   944   apply (rule 3 [temp_use])
   945   apply (simp add: split_box_conj [try_rewrite] NotDmd [temp_use] not_angle [try_rewrite])
   946   done
   947 
   948 lemma SF1:
   949   "[| |- $P & N  --> P` | Q`;    
   950       |- ($P & N) & <A>_v --> Q`;    
   951       |- []P & []N & []F --> <>Enabled(<A>_v) |]    
   952   ==> |- []N & SF(A)_v & []F --> (P ~> Q)"
   953   apply (clarsimp dest!: BoxSFI [temp_use])
   954   apply (erule (2) ensures [temp_use])
   955   apply (erule_tac F = F in dup_boxE)
   956   apply merge_temp_box
   957   apply (erule STL4Edup)
   958   apply assumption
   959   apply (clarsimp simp: SF_def)
   960   apply (rule STL2 [temp_use])
   961   apply (erule mp)
   962   apply (erule STL4 [temp_use])
   963   apply (simp add: split_box_conj [try_rewrite] STL3 [try_rewrite])
   964   done
   965 
   966 lemma WF2:
   967   assumes 1: "|- N & <B>_f --> <M>_g"
   968     and 2: "|- $P & P` & <N & A>_f --> B"
   969     and 3: "|- P & Enabled(<M>_g) --> Enabled(<A>_f)"
   970     and 4: "|- [](N & [~B]_f) & WF(A)_f & []F & <>[]Enabled(<M>_g) --> <>[]P"
   971   shows "|- []N & WF(A)_f & []F --> WF(M)_g"
   972   apply (clarsimp dest!: BoxWFI [temp_use] BoxDmdBox [temp_use, THEN iffD2]
   973     simp: WF_def [where A = M])
   974   apply (erule_tac F = F in dup_boxE)
   975   apply merge_temp_box
   976   apply (erule STL4Edup)
   977    apply assumption
   978   apply (clarsimp intro!: BoxDmd_simple [temp_use, THEN 1 [THEN DmdImpl, temp_use]])
   979   apply (rule classical)
   980   apply (subgoal_tac "sigmaa |= <> (($P & P` & N) & <A>_f)")
   981    apply (force simp: angle_def intro!: 2 [temp_use] elim!: DmdImplE [temp_use])
   982   apply (rule BoxDmd_simple [THEN DmdImpl, unfolded DmdDmd [temp_rewrite], temp_use])
   983   apply (simp add: NotDmd [temp_use] not_angle [try_rewrite])
   984   apply merge_act_box
   985   apply (frule 4 [temp_use])
   986      apply assumption+
   987   apply (drule STL6 [temp_use])
   988    apply assumption
   989   apply (erule_tac V = "sigmaa |= <>[]P" in thin_rl)
   990   apply (erule_tac V = "sigmaa |= []F" in thin_rl)
   991   apply (drule BoxWFI [temp_use])
   992   apply (erule_tac F = "ACT N & [~B]_f" in dup_boxE)
   993   apply merge_temp_box
   994   apply (erule DmdImpldup)
   995    apply assumption
   996   apply (auto simp: split_box_conj [try_rewrite] STL3 [try_rewrite]
   997     WF_Box [try_rewrite] box_stp_act [try_rewrite])
   998    apply (force elim!: TLA2E [where P = P, temp_use])
   999   apply (rule STL2 [temp_use])
  1000   apply (force simp: WF_def split_box_conj [try_rewrite]
  1001     elim!: mp intro!: InitDmd [temp_use] 3 [THEN STL4, temp_use])
  1002   done
  1003 
  1004 lemma SF2:
  1005   assumes 1: "|- N & <B>_f --> <M>_g"
  1006     and 2: "|- $P & P` & <N & A>_f --> B"
  1007     and 3: "|- P & Enabled(<M>_g) --> Enabled(<A>_f)"
  1008     and 4: "|- [](N & [~B]_f) & SF(A)_f & []F & []<>Enabled(<M>_g) --> <>[]P"
  1009   shows "|- []N & SF(A)_f & []F --> SF(M)_g"
  1010   apply (clarsimp dest!: BoxSFI [temp_use] simp: 2 [try_rewrite] SF_def [where A = M])
  1011   apply (erule_tac F = F in dup_boxE)
  1012   apply (erule_tac F = "TEMP <>Enabled (<M>_g) " in dup_boxE)
  1013   apply merge_temp_box
  1014   apply (erule STL4Edup)
  1015    apply assumption
  1016   apply (clarsimp intro!: BoxDmd_simple [temp_use, THEN 1 [THEN DmdImpl, temp_use]])
  1017   apply (rule classical)
  1018   apply (subgoal_tac "sigmaa |= <> (($P & P` & N) & <A>_f)")
  1019    apply (force simp: angle_def intro!: 2 [temp_use] elim!: DmdImplE [temp_use])
  1020   apply (rule BoxDmd_simple [THEN DmdImpl, unfolded DmdDmd [temp_rewrite], temp_use])
  1021   apply (simp add: NotDmd [temp_use] not_angle [try_rewrite])
  1022   apply merge_act_box
  1023   apply (frule 4 [temp_use])
  1024      apply assumption+
  1025   apply (erule_tac V = "sigmaa |= []F" in thin_rl)
  1026   apply (drule BoxSFI [temp_use])
  1027   apply (erule_tac F = "TEMP <>Enabled (<M>_g)" in dup_boxE)
  1028   apply (erule_tac F = "ACT N & [~B]_f" in dup_boxE)
  1029   apply merge_temp_box
  1030   apply (erule DmdImpldup)
  1031    apply assumption
  1032   apply (auto simp: split_box_conj [try_rewrite] STL3 [try_rewrite]
  1033     SF_Box [try_rewrite] box_stp_act [try_rewrite])
  1034    apply (force elim!: TLA2E [where P = P, temp_use])
  1035   apply (rule STL2 [temp_use])
  1036   apply (force simp: SF_def split_box_conj [try_rewrite]
  1037     elim!: mp InfImpl [temp_use] intro!: 3 [temp_use])
  1038   done
  1039 
  1040 (* ------------------------------------------------------------------------- *)
  1041 (***           Liveness proofs by well-founded orderings                   ***)
  1042 (* ------------------------------------------------------------------------- *)
  1043 section "Well-founded orderings"
  1044 
  1045 lemma wf_leadsto:
  1046   assumes 1: "wf r"
  1047     and 2: "!!x. sigma |= F x ~> (G | (EX y. #((y,x):r) & F y))    "
  1048   shows "sigma |= F x ~> G"
  1049   apply (rule 1 [THEN wf_induct])
  1050   apply (rule LatticeTriangle [temp_use])
  1051    apply (rule 2)
  1052   apply (auto simp: leadsto_exists [try_rewrite])
  1053   apply (case_tac "(y,x) :r")
  1054    apply force
  1055   apply (force simp: leadsto_def Init_simps intro!: necT [temp_use])
  1056   done
  1057 
  1058 (* If r is well-founded, state function v cannot decrease forever *)
  1059 lemma wf_not_box_decrease: "!!r. wf r ==> |- [][ (v`, $v) : #r ]_v --> <>[][#False]_v"
  1060   apply clarsimp
  1061   apply (rule ccontr)
  1062   apply (subgoal_tac "sigma |= (EX x. v=#x) ~> #False")
  1063    apply (drule leadsto_false [temp_use, THEN iffD1, THEN STL2_gen [temp_use]])
  1064    apply (force simp: Init_defs)
  1065   apply (clarsimp simp: leadsto_exists [try_rewrite] not_square [try_rewrite] more_temp_simps)
  1066   apply (erule wf_leadsto)
  1067   apply (rule ensures_simple [temp_use])
  1068    apply (auto simp: square_def angle_def)
  1069   done
  1070 
  1071 (* "wf r  ==>  |- <>[][ (v`, $v) : #r ]_v --> <>[][#False]_v" *)
  1072 lemmas wf_not_dmd_box_decrease =
  1073   wf_not_box_decrease [THEN DmdImpl, unfolded more_temp_simps]
  1074 
  1075 (* If there are infinitely many steps where v decreases, then there
  1076    have to be infinitely many non-stuttering steps where v doesn't decrease.
  1077 *)
  1078 lemma wf_box_dmd_decrease:
  1079   assumes 1: "wf r"
  1080   shows "|- []<>((v`, $v) : #r) --> []<><(v`, $v) ~: #r>_v"
  1081   apply clarsimp
  1082   apply (rule ccontr)
  1083   apply (simp add: not_angle [try_rewrite] more_temp_simps)
  1084   apply (drule 1 [THEN wf_not_dmd_box_decrease [temp_use]])
  1085   apply (drule BoxDmdDmdBox [temp_use])
  1086    apply assumption
  1087   apply (subgoal_tac "sigma |= []<> ((#False) ::action)")
  1088    apply force
  1089   apply (erule STL4E)
  1090   apply (rule DmdImpl)
  1091   apply (force intro: 1 [THEN wf_irrefl, temp_use])
  1092   done
  1093 
  1094 (* In particular, for natural numbers, if n decreases infinitely often
  1095    then it has to increase infinitely often.
  1096 *)
  1097 lemma nat_box_dmd_decrease: "!!n::nat stfun. |- []<>(n` < $n) --> []<>($n < n`)"
  1098   apply clarsimp
  1099   apply (subgoal_tac "sigma |= []<><~ ((n`,$n) : #less_than) >_n")
  1100    apply (erule thin_rl)
  1101    apply (erule STL4E)
  1102    apply (rule DmdImpl)
  1103    apply (clarsimp simp: angle_def [try_rewrite])
  1104   apply (rule wf_box_dmd_decrease [temp_use])
  1105    apply (auto elim!: STL4E [temp_use] DmdImplE [temp_use])
  1106   done
  1107 
  1108 
  1109 (* ------------------------------------------------------------------------- *)
  1110 (***           Flexible quantification over state variables                ***)
  1111 (* ------------------------------------------------------------------------- *)
  1112 section "Flexible quantification"
  1113 
  1114 lemma aallI:
  1115   assumes 1: "basevars vs"
  1116     and 2: "(!!x. basevars (x,vs) ==> sigma |= F x)"
  1117   shows "sigma |= (AALL x. F x)"
  1118   by (auto simp: aall_def elim!: eexE [temp_use] intro!: 1 dest!: 2 [temp_use])
  1119 
  1120 lemma aallE: "|- (AALL x. F x) --> F x"
  1121   apply (unfold aall_def)
  1122   apply clarsimp
  1123   apply (erule contrapos_np)
  1124   apply (force intro!: eexI [temp_use])
  1125   done
  1126 
  1127 (* monotonicity of quantification *)
  1128 lemma eex_mono:
  1129   assumes 1: "sigma |= EEX x. F x"
  1130     and 2: "!!x. sigma |= F x --> G x"
  1131   shows "sigma |= EEX x. G x"
  1132   apply (rule unit_base [THEN 1 [THEN eexE]])
  1133   apply (rule eexI [temp_use])
  1134   apply (erule 2 [unfolded intensional_rews, THEN mp])
  1135   done
  1136 
  1137 lemma aall_mono:
  1138   assumes 1: "sigma |= AALL x. F(x)"
  1139     and 2: "!!x. sigma |= F(x) --> G(x)"
  1140   shows "sigma |= AALL x. G(x)"
  1141   apply (rule unit_base [THEN aallI])
  1142   apply (rule 2 [unfolded intensional_rews, THEN mp])
  1143   apply (rule 1 [THEN aallE [temp_use]])
  1144   done
  1145 
  1146 (* Derived history introduction rule *)
  1147 lemma historyI:
  1148   assumes 1: "sigma |= Init I"
  1149     and 2: "sigma |= []N"
  1150     and 3: "basevars vs"
  1151     and 4: "!!h. basevars(h,vs) ==> |- I & h = ha --> HI h"
  1152     and 5: "!!h s t. [| basevars(h,vs); N (s,t); h t = hb (h s) (s,t) |] ==> HN h (s,t)"
  1153   shows "sigma |= EEX h. Init (HI h) & [](HN h)"
  1154   apply (rule history [temp_use, THEN eexE])
  1155   apply (rule 3)
  1156   apply (rule eexI [temp_use])
  1157   apply clarsimp
  1158   apply (rule conjI)
  1159    prefer 2
  1160    apply (insert 2)
  1161    apply merge_box
  1162    apply (force elim!: STL4E [temp_use] 5 [temp_use])
  1163   apply (insert 1)
  1164   apply (force simp: Init_defs elim!: 4 [temp_use])
  1165   done
  1166 
  1167 (* ----------------------------------------------------------------------
  1168    example of a history variable: existence of a clock
  1169 *)
  1170 
  1171 lemma "|- EEX h. Init(h = #True) & [](h` = (~$h))"
  1172   apply (rule tempI)
  1173   apply (rule historyI)
  1174   apply (force simp: Init_defs intro!: unit_base [temp_use] necT [temp_use])+
  1175   done
  1176 
  1177 end