src/HOL/TLA/Action.thy
author krauss
Sat, 07 Apr 2007 18:54:30 +0200
changeset 22612 1f017e6a0395
parent 21624 6f79647cf536
child 24180 9f818139951b
permissions -rw-r--r--
removed obsolete workarounds
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
     1
(*
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
     2
    File:        TLA/Action.thy
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
     3
    ID:          $Id$
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
     4
    Author:      Stephan Merz
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
     5
    Copyright:   1998 University of Munich
21624
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
     6
*)
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
     7
21624
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
     8
header {* The action level of TLA as an Isabelle theory *}
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
     9
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    10
theory Action
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    11
imports Stfun
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    12
begin
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    13
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    14
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    15
(** abstract syntax **)
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    16
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    17
types
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    18
  'a trfun = "(state * state) => 'a"
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    19
  action   = "bool trfun"
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    20
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    21
instance
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    22
  "*" :: (world, world) world ..
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    23
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    24
consts
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    25
  (** abstract syntax **)
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    26
  before        :: "'a stfun => 'a trfun"
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    27
  after         :: "'a stfun => 'a trfun"
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    28
  unch          :: "'a stfun => action"
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    29
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    30
  SqAct         :: "[action, 'a stfun] => action"
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    31
  AnAct         :: "[action, 'a stfun] => action"
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    32
  enabled       :: "action => stpred"
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    33
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    34
(** concrete syntax **)
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    35
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    36
syntax
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    37
  (* Syntax for writing action expressions in arbitrary contexts *)
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    38
  "ACT"         :: "lift => 'a"                      ("(ACT _)")
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    39
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    40
  "_before"     :: "lift => lift"                    ("($_)"  [100] 99)
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    41
  "_after"      :: "lift => lift"                    ("(_$)"  [100] 99)
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    42
  "_unchanged"  :: "lift => lift"                    ("(unchanged _)" [100] 99)
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    43
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    44
  (*** Priming: same as "after" ***)
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    45
  "_prime"      :: "lift => lift"                    ("(_`)" [100] 99)
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    46
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    47
  "_SqAct"      :: "[lift, lift] => lift"            ("([_]'_(_))" [0,1000] 99)
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    48
  "_AnAct"      :: "[lift, lift] => lift"            ("(<_>'_(_))" [0,1000] 99)
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    49
  "_Enabled"    :: "lift => lift"                    ("(Enabled _)" [100] 100)
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    50
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    51
translations
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    52
  "ACT A"            =>   "(A::state*state => _)"
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    53
  "_before"          ==   "before"
9517
f58863b1406a tuned version by Stephan Merz (unbatchified etc.);
wenzelm
parents: 6255
diff changeset
    54
  "_after"           ==   "after"
f58863b1406a tuned version by Stephan Merz (unbatchified etc.);
wenzelm
parents: 6255
diff changeset
    55
  "_prime"           =>   "_after"
6255
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    56
  "_unchanged"       ==   "unch"
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    57
  "_SqAct"           ==   "SqAct"
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    58
  "_AnAct"           ==   "AnAct"
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    59
  "_Enabled"         ==   "enabled"
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    60
  "w |= [A]_v"       <=   "_SqAct A v w"
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    61
  "w |= <A>_v"       <=   "_AnAct A v w"
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    62
  "s |= Enabled A"   <=   "_Enabled A s"
db63752140c7 updated (Stephan Merz);
wenzelm
parents: 3807
diff changeset
    63
  "w |= unchanged f" <=   "_unchanged f w"
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    64
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    65
axioms
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    66
  unl_before:    "(ACT $v) (s,t) == v s"
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    67
  unl_after:     "(ACT v$) (s,t) == v t"
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    68
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    69
  unchanged_def: "(s,t) |= unchanged v == (v t = v s)"
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    70
  square_def:    "ACT [A]_v == ACT (A | unchanged v)"
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    71
  angle_def:     "ACT <A>_v == ACT (A & ~ unchanged v)"
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
    72
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    73
  enabled_def:   "s |= Enabled A  ==  EX u. (s,u) |= A"
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
    74
21624
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    75
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    76
(* The following assertion specializes "intI" for any world type
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    77
   which is a pair, not just for "state * state".
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    78
*)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    79
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    80
lemma actionI [intro!]:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    81
  assumes "!!s t. (s,t) |= A"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    82
  shows "|- A"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    83
  apply (rule assms intI prod_induct)+
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    84
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    85
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    86
lemma actionD [dest]: "|- A ==> (s,t) |= A"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    87
  apply (erule intD)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    88
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    89
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    90
lemma pr_rews [int_rewrite]:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    91
  "|- (#c)` = #c"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    92
  "!!f. |- f<x>` = f<x` >"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    93
  "!!f. |- f<x,y>` = f<x`,y` >"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    94
  "!!f. |- f<x,y,z>` = f<x`,y`,z` >"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    95
  "|- (! x. P x)` = (! x. (P x)`)"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    96
  "|- (? x. P x)` = (? x. (P x)`)"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    97
  by (rule actionI, unfold unl_after intensional_rews, rule refl)+
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    98
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
    99
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   100
lemmas act_rews [simp] = unl_before unl_after unchanged_def pr_rews
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   101
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   102
lemmas action_rews = act_rews intensional_rews
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   103
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   104
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   105
(* ================ Functions to "unlift" action theorems into HOL rules ================ *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   106
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   107
ML {*
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   108
(* The following functions are specialized versions of the corresponding
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   109
   functions defined in Intensional.ML in that they introduce a
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   110
   "world" parameter of the form (s,t) and apply additional rewrites.
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   111
*)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   112
local
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   113
  val action_rews = thms "action_rews";
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   114
  val actionD = thm "actionD";
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   115
in
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   116
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   117
fun action_unlift th =
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   118
  (rewrite_rule action_rews (th RS actionD))
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   119
    handle THM _ => int_unlift th;
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   120
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   121
(* Turn  |- A = B  into meta-level rewrite rule  A == B *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   122
val action_rewrite = int_rewrite
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   123
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   124
fun action_use th =
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   125
    case (concl_of th) of
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   126
      Const _ $ (Const ("Intensional.Valid", _) $ _) =>
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   127
              (flatten (action_unlift th) handle THM _ => th)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   128
    | _ => th;
17309
c43ed29bd197 converted to Isar theory format;
wenzelm
parents: 11703
diff changeset
   129
3807
82a99b090d9d A formalization of TLA in HOL -- by Stephan Merz;
wenzelm
parents:
diff changeset
   130
end
21624
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   131
*}
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   132
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   133
setup {*
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   134
  Attrib.add_attributes [
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   135
    ("action_unlift", Attrib.no_args (Thm.rule_attribute (K action_unlift)), ""),
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   136
    ("action_rewrite", Attrib.no_args (Thm.rule_attribute (K action_rewrite)), ""),
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   137
    ("action_use", Attrib.no_args (Thm.rule_attribute (K action_use)), "")]
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   138
*}
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   139
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   140
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   141
(* =========================== square / angle brackets =========================== *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   142
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   143
lemma idle_squareI: "(s,t) |= unchanged v ==> (s,t) |= [A]_v"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   144
  by (simp add: square_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   145
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   146
lemma busy_squareI: "(s,t) |= A ==> (s,t) |= [A]_v"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   147
  by (simp add: square_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   148
  
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   149
lemma squareE [elim]:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   150
  "[| (s,t) |= [A]_v; A (s,t) ==> B (s,t); v t = v s ==> B (s,t) |] ==> B (s,t)"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   151
  apply (unfold square_def action_rews)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   152
  apply (erule disjE)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   153
  apply simp_all
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   154
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   155
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   156
lemma squareCI [intro]: "[| v t ~= v s ==> A (s,t) |] ==> (s,t) |= [A]_v"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   157
  apply (unfold square_def action_rews)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   158
  apply (rule disjCI)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   159
  apply (erule (1) meta_mp)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   160
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   161
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   162
lemma angleI [intro]: "!!s t. [| A (s,t); v t ~= v s |] ==> (s,t) |= <A>_v"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   163
  by (simp add: angle_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   164
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   165
lemma angleE [elim]: "[| (s,t) |= <A>_v; [| A (s,t); v t ~= v s |] ==> R |] ==> R"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   166
  apply (unfold angle_def action_rews)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   167
  apply (erule conjE)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   168
  apply simp
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   169
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   170
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   171
lemma square_simulation:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   172
   "!!f. [| |- unchanged f & ~B --> unchanged g;    
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   173
            |- A & ~unchanged g --> B               
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   174
         |] ==> |- [A]_f --> [B]_g"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   175
  apply clarsimp
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   176
  apply (erule squareE)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   177
  apply (auto simp add: square_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   178
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   179
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   180
lemma not_square: "|- (~ [A]_v) = <~A>_v"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   181
  by (auto simp: square_def angle_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   182
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   183
lemma not_angle: "|- (~ <A>_v) = [~A]_v"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   184
  by (auto simp: square_def angle_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   185
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   186
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   187
(* ============================== Facts about ENABLED ============================== *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   188
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   189
lemma enabledI: "|- A --> $Enabled A"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   190
  by (auto simp add: enabled_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   191
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   192
lemma enabledE: "[| s |= Enabled A; !!u. A (s,u) ==> Q |] ==> Q"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   193
  apply (unfold enabled_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   194
  apply (erule exE)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   195
  apply simp
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   196
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   197
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   198
lemma notEnabledD: "|- ~$Enabled G --> ~ G"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   199
  by (auto simp add: enabled_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   200
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   201
(* Monotonicity *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   202
lemma enabled_mono:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   203
  assumes min: "s |= Enabled F"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   204
    and maj: "|- F --> G"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   205
  shows "s |= Enabled G"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   206
  apply (rule min [THEN enabledE])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   207
  apply (rule enabledI [action_use])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   208
  apply (erule maj [action_use])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   209
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   210
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   211
(* stronger variant *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   212
lemma enabled_mono2:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   213
  assumes min: "s |= Enabled F"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   214
    and maj: "!!t. F (s,t) ==> G (s,t)"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   215
  shows "s |= Enabled G"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   216
  apply (rule min [THEN enabledE])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   217
  apply (rule enabledI [action_use])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   218
  apply (erule maj)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   219
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   220
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   221
lemma enabled_disj1: "|- Enabled F --> Enabled (F | G)"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   222
  by (auto elim!: enabled_mono)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   223
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   224
lemma enabled_disj2: "|- Enabled G --> Enabled (F | G)"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   225
  by (auto elim!: enabled_mono)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   226
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   227
lemma enabled_conj1: "|- Enabled (F & G) --> Enabled F"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   228
  by (auto elim!: enabled_mono)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   229
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   230
lemma enabled_conj2: "|- Enabled (F & G) --> Enabled G"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   231
  by (auto elim!: enabled_mono)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   232
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   233
lemma enabled_conjE:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   234
    "[| s |= Enabled (F & G); [| s |= Enabled F; s |= Enabled G |] ==> Q |] ==> Q"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   235
  apply (frule enabled_conj1 [action_use])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   236
  apply (drule enabled_conj2 [action_use])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   237
  apply simp
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   238
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   239
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   240
lemma enabled_disjD: "|- Enabled (F | G) --> Enabled F | Enabled G"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   241
  by (auto simp add: enabled_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   242
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   243
lemma enabled_disj: "|- Enabled (F | G) = (Enabled F | Enabled G)"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   244
  apply clarsimp
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   245
  apply (rule iffI)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   246
   apply (erule enabled_disjD [action_use])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   247
  apply (erule disjE enabled_disj1 [action_use] enabled_disj2 [action_use])+
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   248
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   249
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   250
lemma enabled_ex: "|- Enabled (EX x. F x) = (EX x. Enabled (F x))"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   251
  by (force simp add: enabled_def)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   252
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   253
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   254
(* A rule that combines enabledI and baseE, but generates fewer instantiations *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   255
lemma base_enabled:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   256
    "[| basevars vs; EX c. ! u. vs u = c --> A(s,u) |] ==> s |= Enabled A"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   257
  apply (erule exE)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   258
  apply (erule baseE)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   259
  apply (rule enabledI [action_use])
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   260
  apply (erule allE)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   261
  apply (erule mp)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   262
  apply assumption
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   263
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   264
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   265
(* ======================= action_simp_tac ============================== *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   266
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   267
ML {*
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   268
(* A dumb simplification-based tactic with just a little first-order logic:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   269
   should plug in only "very safe" rules that can be applied blindly.
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   270
   Note that it applies whatever simplifications are currently active.
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   271
*)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   272
local
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   273
  val actionI = thm "actionI";
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   274
  val intI = thm "intI";
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   275
in
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   276
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   277
fun action_simp_tac ss intros elims =
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   278
    asm_full_simp_tac
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   279
         (ss setloop ((resolve_tac ((map action_use intros)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   280
                                    @ [refl,impI,conjI,actionI,intI,allI]))
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   281
                      ORELSE' (eresolve_tac ((map action_use elims)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   282
                                             @ [conjE,disjE,exE]))));
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   283
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   284
(* default version without additional plug-in rules *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   285
val Action_simp_tac = action_simp_tac (simpset()) [] []
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   286
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   287
end
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   288
*}
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   289
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   290
(* ---------------- enabled_tac: tactic to prove (Enabled A) -------------------- *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   291
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   292
ML {*
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   293
(* "Enabled A" can be proven as follows:
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   294
   - Assume that we know which state variables are "base variables"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   295
     this should be expressed by a theorem of the form "basevars (x,y,z,...)".
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   296
   - Resolve this theorem with baseE to introduce a constant for the value of the
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   297
     variables in the successor state, and resolve the goal with the result.
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   298
   - Resolve with enabledI and do some rewriting.
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   299
   - Solve for the unknowns using standard HOL reasoning.
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   300
   The following tactic combines these steps except the final one.
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   301
*)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   302
local
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   303
  val base_enabled = thm "base_enabled";
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   304
in
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   305
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   306
fun enabled_tac base_vars =
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   307
  clarsimp_tac (claset() addSIs [base_vars RS base_enabled], simpset());
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   308
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   309
end
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   310
*}
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   311
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   312
(* Example *)
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   313
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   314
lemma
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   315
  assumes "basevars (x,y,z)"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   316
  shows "|- x --> Enabled ($x & (y$ = #False))"
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   317
  apply (tactic {* enabled_tac (thm "assms") 1 *})
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   318
  apply auto
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   319
  done
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   320
6f79647cf536 TLA: converted legacy ML scripts;
wenzelm
parents: 17309
diff changeset
   321
end