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