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