src/HOL/UNITY/UNITY.thy
author paulson
Tue Feb 04 18:12:40 2003 +0100 (2003-02-04)
changeset 13805 3786b2fd6808
parent 13798 4c1a53627500
child 13812 91713a1915ee
permissions -rw-r--r--
some x-symbols
paulson@4776
     1
(*  Title:      HOL/UNITY/UNITY
paulson@4776
     2
    ID:         $Id$
paulson@4776
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@4776
     4
    Copyright   1998  University of Cambridge
paulson@4776
     5
paulson@4776
     6
The basic UNITY theory (revised version, based upon the "co" operator)
paulson@4776
     7
paulson@4776
     8
From Misra, "A Logic for Concurrent Programming", 1994
paulson@4776
     9
*)
paulson@4776
    10
paulson@13798
    11
header {*The Basic UNITY Theory*}
paulson@13798
    12
paulson@13797
    13
theory UNITY = Main:
paulson@6535
    14
paulson@6535
    15
typedef (Program)
paulson@10064
    16
  'a program = "{(init:: 'a set, acts :: ('a * 'a)set set,
paulson@13805
    17
		   allowed :: ('a * 'a)set set). Id \<in> acts & Id: allowed}" 
paulson@13797
    18
  by blast
paulson@6536
    19
paulson@4776
    20
constdefs
paulson@13797
    21
  constrains :: "['a set, 'a set] => 'a program set"  (infixl "co"     60)
paulson@13805
    22
    "A co B == {F. \<forall>act \<in> Acts F. act``A \<subseteq> B}"
paulson@13797
    23
paulson@13797
    24
  unless  :: "['a set, 'a set] => 'a program set"  (infixl "unless" 60)
paulson@13805
    25
    "A unless B == (A-B) co (A \<union> B)"
paulson@13797
    26
paulson@13797
    27
  mk_program :: "('a set * ('a * 'a)set set * ('a * 'a)set set)
paulson@10064
    28
		   => 'a program"
paulson@10064
    29
    "mk_program == %(init, acts, allowed).
paulson@10064
    30
                      Abs_Program (init, insert Id acts, insert Id allowed)"
paulson@6535
    31
paulson@6535
    32
  Init :: "'a program => 'a set"
paulson@10064
    33
    "Init F == (%(init, acts, allowed). init) (Rep_Program F)"
paulson@6535
    34
paulson@6535
    35
  Acts :: "'a program => ('a * 'a)set set"
paulson@10064
    36
    "Acts F == (%(init, acts, allowed). acts) (Rep_Program F)"
paulson@10064
    37
paulson@10064
    38
  AllowedActs :: "'a program => ('a * 'a)set set"
paulson@10064
    39
    "AllowedActs F == (%(init, acts, allowed). allowed) (Rep_Program F)"
paulson@10064
    40
paulson@10064
    41
  Allowed :: "'a program => 'a program set"
paulson@13805
    42
    "Allowed F == {G. Acts G \<subseteq> AllowedActs F}"
paulson@4776
    43
paulson@5648
    44
  stable     :: "'a set => 'a program set"
paulson@6536
    45
    "stable A == A co A"
paulson@4776
    46
paulson@5648
    47
  strongest_rhs :: "['a program, 'a set] => 'a set"
paulson@13805
    48
    "strongest_rhs F A == Inter {B. F \<in> A co B}"
paulson@4776
    49
paulson@5648
    50
  invariant :: "'a set => 'a program set"
paulson@13805
    51
    "invariant A == {F. Init F \<subseteq> A} \<inter> stable A"
paulson@4776
    52
paulson@13805
    53
  (*Polymorphic in both states and the meaning of \<le> *)
paulson@6713
    54
  increasing :: "['a => 'b::{order}] => 'a program set"
paulson@13805
    55
    "increasing f == \<Inter>z. stable {s. z \<le> f s}"
paulson@4776
    56
paulson@6536
    57
paulson@13797
    58
(*Perhaps equalities.ML shouldn't add this in the first place!*)
paulson@13797
    59
declare image_Collect [simp del]
paulson@13797
    60
paulson@13797
    61
(*** The abstract type of programs ***)
paulson@13797
    62
paulson@13797
    63
lemmas program_typedef =
paulson@13797
    64
     Rep_Program Rep_Program_inverse Abs_Program_inverse 
paulson@13797
    65
     Program_def Init_def Acts_def AllowedActs_def mk_program_def
paulson@13797
    66
paulson@13805
    67
lemma Id_in_Acts [iff]: "Id \<in> Acts F"
paulson@13797
    68
apply (cut_tac x = F in Rep_Program)
paulson@13797
    69
apply (auto simp add: program_typedef) 
paulson@13797
    70
done
paulson@13797
    71
paulson@13797
    72
lemma insert_Id_Acts [iff]: "insert Id (Acts F) = Acts F"
paulson@13797
    73
by (simp add: insert_absorb Id_in_Acts)
paulson@13797
    74
paulson@13805
    75
lemma Id_in_AllowedActs [iff]: "Id \<in> AllowedActs F"
paulson@13797
    76
apply (cut_tac x = F in Rep_Program)
paulson@13797
    77
apply (auto simp add: program_typedef) 
paulson@13797
    78
done
paulson@13797
    79
paulson@13797
    80
lemma insert_Id_AllowedActs [iff]: "insert Id (AllowedActs F) = AllowedActs F"
paulson@13797
    81
by (simp add: insert_absorb Id_in_AllowedActs)
paulson@13797
    82
paulson@13797
    83
(** Inspectors for type "program" **)
paulson@13797
    84
paulson@13797
    85
lemma Init_eq [simp]: "Init (mk_program (init,acts,allowed)) = init"
paulson@13797
    86
by (auto simp add: program_typedef)
paulson@13797
    87
paulson@13797
    88
lemma Acts_eq [simp]: "Acts (mk_program (init,acts,allowed)) = insert Id acts"
paulson@13797
    89
by (auto simp add: program_typedef)
paulson@13797
    90
paulson@13797
    91
lemma AllowedActs_eq [simp]:
paulson@13797
    92
     "AllowedActs (mk_program (init,acts,allowed)) = insert Id allowed"
paulson@13797
    93
by (auto simp add: program_typedef)
paulson@13797
    94
paulson@13797
    95
(** Equality for UNITY programs **)
paulson@13797
    96
paulson@13797
    97
lemma surjective_mk_program [simp]:
paulson@13797
    98
     "mk_program (Init F, Acts F, AllowedActs F) = F"
paulson@13797
    99
apply (cut_tac x = F in Rep_Program)
paulson@13797
   100
apply (auto simp add: program_typedef)
paulson@13797
   101
apply (drule_tac f = Abs_Program in arg_cong)+
paulson@13797
   102
apply (simp add: program_typedef insert_absorb)
paulson@13797
   103
done
paulson@13797
   104
paulson@13797
   105
lemma program_equalityI:
paulson@13797
   106
     "[| Init F = Init G; Acts F = Acts G; AllowedActs F = AllowedActs G |]  
paulson@13797
   107
      ==> F = G"
paulson@13797
   108
apply (rule_tac t = F in surjective_mk_program [THEN subst])
paulson@13797
   109
apply (rule_tac t = G in surjective_mk_program [THEN subst], simp)
paulson@13797
   110
done
paulson@13797
   111
paulson@13797
   112
lemma program_equalityE:
paulson@13797
   113
     "[| F = G;  
paulson@13797
   114
         [| Init F = Init G; Acts F = Acts G; AllowedActs F = AllowedActs G |] 
paulson@13797
   115
         ==> P |] ==> P"
paulson@13797
   116
by simp 
paulson@13797
   117
paulson@13797
   118
lemma program_equality_iff:
paulson@13797
   119
     "(F=G) =   
paulson@13797
   120
      (Init F = Init G & Acts F = Acts G &AllowedActs F = AllowedActs G)"
paulson@13797
   121
by (blast intro: program_equalityI program_equalityE)
paulson@13797
   122
paulson@13797
   123
paulson@13797
   124
(*** These rules allow "lazy" definition expansion 
paulson@13797
   125
     They avoid expanding the full program, which is a large expression
paulson@13797
   126
***)
paulson@13797
   127
paulson@13797
   128
lemma def_prg_Init: "F == mk_program (init,acts,allowed) ==> Init F = init"
paulson@13797
   129
by auto
paulson@13797
   130
paulson@13797
   131
lemma def_prg_Acts:
paulson@13797
   132
     "F == mk_program (init,acts,allowed) ==> Acts F = insert Id acts"
paulson@13797
   133
by auto
paulson@13797
   134
paulson@13797
   135
lemma def_prg_AllowedActs:
paulson@13797
   136
     "F == mk_program (init,acts,allowed)  
paulson@13797
   137
      ==> AllowedActs F = insert Id allowed"
paulson@13797
   138
by auto
paulson@13797
   139
paulson@13797
   140
(*The program is not expanded, but its Init and Acts are*)
paulson@13797
   141
lemma def_prg_simps:
paulson@13797
   142
    "[| F == mk_program (init,acts,allowed) |]  
paulson@13797
   143
     ==> Init F = init & Acts F = insert Id acts"
paulson@13797
   144
by simp
paulson@13797
   145
paulson@13797
   146
(*An action is expanded only if a pair of states is being tested against it*)
paulson@13797
   147
lemma def_act_simp:
paulson@13805
   148
     "[| act == {(s,s'). P s s'} |] ==> ((s,s') \<in> act) = P s s'"
paulson@13797
   149
by auto
paulson@13797
   150
paulson@13797
   151
(*A set is expanded only if an element is being tested against it*)
paulson@13805
   152
lemma def_set_simp: "A == B ==> (x \<in> A) = (x \<in> B)"
paulson@13797
   153
by auto
paulson@13797
   154
paulson@13797
   155
paulson@13797
   156
(*** co ***)
paulson@13797
   157
paulson@13797
   158
lemma constrainsI: 
paulson@13805
   159
    "(!!act s s'. [| act: Acts F;  (s,s') \<in> act;  s \<in> A |] ==> s': A')  
paulson@13805
   160
     ==> F \<in> A co A'"
paulson@13797
   161
by (simp add: constrains_def, blast)
paulson@13797
   162
paulson@13797
   163
lemma constrainsD: 
paulson@13805
   164
    "[| F \<in> A co A'; act: Acts F;  (s,s'): act;  s \<in> A |] ==> s': A'"
paulson@13797
   165
by (unfold constrains_def, blast)
paulson@13797
   166
paulson@13805
   167
lemma constrains_empty [iff]: "F \<in> {} co B"
paulson@13797
   168
by (unfold constrains_def, blast)
paulson@13797
   169
paulson@13805
   170
lemma constrains_empty2 [iff]: "(F \<in> A co {}) = (A={})"
paulson@13797
   171
by (unfold constrains_def, blast)
paulson@13797
   172
paulson@13805
   173
lemma constrains_UNIV [iff]: "(F \<in> UNIV co B) = (B = UNIV)"
paulson@13797
   174
by (unfold constrains_def, blast)
paulson@13797
   175
paulson@13805
   176
lemma constrains_UNIV2 [iff]: "F \<in> A co UNIV"
paulson@13797
   177
by (unfold constrains_def, blast)
paulson@13797
   178
paulson@13797
   179
(*monotonic in 2nd argument*)
paulson@13797
   180
lemma constrains_weaken_R: 
paulson@13805
   181
    "[| F \<in> A co A'; A'<=B' |] ==> F \<in> A co B'"
paulson@13797
   182
by (unfold constrains_def, blast)
paulson@13797
   183
paulson@13797
   184
(*anti-monotonic in 1st argument*)
paulson@13797
   185
lemma constrains_weaken_L: 
paulson@13805
   186
    "[| F \<in> A co A'; B \<subseteq> A |] ==> F \<in> B co A'"
paulson@13797
   187
by (unfold constrains_def, blast)
paulson@13797
   188
paulson@13797
   189
lemma constrains_weaken: 
paulson@13805
   190
   "[| F \<in> A co A'; B \<subseteq> A; A'<=B' |] ==> F \<in> B co B'"
paulson@13797
   191
by (unfold constrains_def, blast)
paulson@13797
   192
paulson@13797
   193
(** Union **)
paulson@13797
   194
paulson@13797
   195
lemma constrains_Un: 
paulson@13805
   196
    "[| F \<in> A co A'; F \<in> B co B' |] ==> F \<in> (A \<union> B) co (A' \<union> B')"
paulson@13797
   197
by (unfold constrains_def, blast)
paulson@13797
   198
paulson@13797
   199
lemma constrains_UN: 
paulson@13805
   200
    "(!!i. i \<in> I ==> F \<in> (A i) co (A' i)) 
paulson@13805
   201
     ==> F \<in> (\<Union>i \<in> I. A i) co (\<Union>i \<in> I. A' i)"
paulson@13797
   202
by (unfold constrains_def, blast)
paulson@13797
   203
paulson@13805
   204
lemma constrains_Un_distrib: "(A \<union> B) co C = (A co C) \<inter> (B co C)"
paulson@13797
   205
by (unfold constrains_def, blast)
paulson@13797
   206
paulson@13805
   207
lemma constrains_UN_distrib: "(\<Union>i \<in> I. A i) co B = (\<Inter>i \<in> I. A i co B)"
paulson@13797
   208
by (unfold constrains_def, blast)
paulson@13797
   209
paulson@13805
   210
lemma constrains_Int_distrib: "C co (A \<inter> B) = (C co A) \<inter> (C co B)"
paulson@13797
   211
by (unfold constrains_def, blast)
paulson@13797
   212
paulson@13805
   213
lemma constrains_INT_distrib: "A co (\<Inter>i \<in> I. B i) = (\<Inter>i \<in> I. A co B i)"
paulson@13797
   214
by (unfold constrains_def, blast)
paulson@13797
   215
paulson@13797
   216
(** Intersection **)
paulson@6536
   217
paulson@13797
   218
lemma constrains_Int: 
paulson@13805
   219
    "[| F \<in> A co A'; F \<in> B co B' |] ==> F \<in> (A \<inter> B) co (A' \<inter> B')"
paulson@13797
   220
by (unfold constrains_def, blast)
paulson@13797
   221
paulson@13797
   222
lemma constrains_INT: 
paulson@13805
   223
    "(!!i. i \<in> I ==> F \<in> (A i) co (A' i)) 
paulson@13805
   224
     ==> F \<in> (\<Inter>i \<in> I. A i) co (\<Inter>i \<in> I. A' i)"
paulson@13797
   225
by (unfold constrains_def, blast)
paulson@13797
   226
paulson@13805
   227
lemma constrains_imp_subset: "F \<in> A co A' ==> A \<subseteq> A'"
paulson@13797
   228
by (unfold constrains_def, auto)
paulson@13797
   229
paulson@13797
   230
(*The reasoning is by subsets since "co" refers to single actions
paulson@13797
   231
  only.  So this rule isn't that useful.*)
paulson@13797
   232
lemma constrains_trans: 
paulson@13805
   233
    "[| F \<in> A co B; F \<in> B co C |] ==> F \<in> A co C"
paulson@13797
   234
by (unfold constrains_def, blast)
paulson@13797
   235
paulson@13797
   236
lemma constrains_cancel: 
paulson@13805
   237
   "[| F \<in> A co (A' \<union> B); F \<in> B co B' |] ==> F \<in> A co (A' \<union> B')"
paulson@13797
   238
by (unfold constrains_def, clarify, blast)
paulson@13797
   239
paulson@13797
   240
paulson@13797
   241
(*** unless ***)
paulson@13797
   242
paulson@13805
   243
lemma unlessI: "F \<in> (A-B) co (A \<union> B) ==> F \<in> A unless B"
paulson@13797
   244
by (unfold unless_def, assumption)
paulson@13797
   245
paulson@13805
   246
lemma unlessD: "F \<in> A unless B ==> F \<in> (A-B) co (A \<union> B)"
paulson@13797
   247
by (unfold unless_def, assumption)
paulson@13797
   248
paulson@13797
   249
paulson@13797
   250
(*** stable ***)
paulson@13797
   251
paulson@13805
   252
lemma stableI: "F \<in> A co A ==> F \<in> stable A"
paulson@13797
   253
by (unfold stable_def, assumption)
paulson@13797
   254
paulson@13805
   255
lemma stableD: "F \<in> stable A ==> F \<in> A co A"
paulson@13797
   256
by (unfold stable_def, assumption)
paulson@13797
   257
paulson@13797
   258
lemma stable_UNIV [simp]: "stable UNIV = UNIV"
paulson@13797
   259
by (unfold stable_def constrains_def, auto)
paulson@13797
   260
paulson@13797
   261
(** Union **)
paulson@13797
   262
paulson@13797
   263
lemma stable_Un: 
paulson@13805
   264
    "[| F \<in> stable A; F \<in> stable A' |] ==> F \<in> stable (A \<union> A')"
paulson@13797
   265
paulson@13797
   266
apply (unfold stable_def)
paulson@13797
   267
apply (blast intro: constrains_Un)
paulson@13797
   268
done
paulson@13797
   269
paulson@13797
   270
lemma stable_UN: 
paulson@13805
   271
    "(!!i. i \<in> I ==> F \<in> stable (A i)) ==> F \<in> stable (\<Union>i \<in> I. A i)"
paulson@13797
   272
apply (unfold stable_def)
paulson@13797
   273
apply (blast intro: constrains_UN)
paulson@13797
   274
done
paulson@13797
   275
paulson@13797
   276
(** Intersection **)
paulson@13797
   277
paulson@13797
   278
lemma stable_Int: 
paulson@13805
   279
    "[| F \<in> stable A;  F \<in> stable A' |] ==> F \<in> stable (A \<inter> A')"
paulson@13797
   280
apply (unfold stable_def)
paulson@13797
   281
apply (blast intro: constrains_Int)
paulson@13797
   282
done
paulson@13797
   283
paulson@13797
   284
lemma stable_INT: 
paulson@13805
   285
    "(!!i. i \<in> I ==> F \<in> stable (A i)) ==> F \<in> stable (\<Inter>i \<in> I. A i)"
paulson@13797
   286
apply (unfold stable_def)
paulson@13797
   287
apply (blast intro: constrains_INT)
paulson@13797
   288
done
paulson@13797
   289
paulson@13797
   290
lemma stable_constrains_Un: 
paulson@13805
   291
    "[| F \<in> stable C; F \<in> A co (C \<union> A') |] ==> F \<in> (C \<union> A) co (C \<union> A')"
paulson@13797
   292
by (unfold stable_def constrains_def, blast)
paulson@13797
   293
paulson@13797
   294
lemma stable_constrains_Int: 
paulson@13805
   295
  "[| F \<in> stable C; F \<in>  (C \<inter> A) co A' |] ==> F \<in> (C \<inter> A) co (C \<inter> A')"
paulson@13797
   296
by (unfold stable_def constrains_def, blast)
paulson@13797
   297
paulson@13805
   298
(*[| F \<in> stable C; F \<in>  (C \<inter> A) co A |] ==> F \<in> stable (C \<inter> A) *)
paulson@13797
   299
lemmas stable_constrains_stable = stable_constrains_Int [THEN stableI, standard]
paulson@13797
   300
paulson@13797
   301
paulson@13797
   302
(*** invariant ***)
paulson@13797
   303
paulson@13805
   304
lemma invariantI: "[| Init F \<subseteq> A;  F \<in> stable A |] ==> F \<in> invariant A"
paulson@13797
   305
by (simp add: invariant_def)
paulson@13797
   306
paulson@13805
   307
(*Could also say "invariant A \<inter> invariant B \<subseteq> invariant (A \<inter> B)"*)
paulson@13797
   308
lemma invariant_Int:
paulson@13805
   309
     "[| F \<in> invariant A;  F \<in> invariant B |] ==> F \<in> invariant (A \<inter> B)"
paulson@13797
   310
by (auto simp add: invariant_def stable_Int)
paulson@13797
   311
paulson@13797
   312
paulson@13797
   313
(*** increasing ***)
paulson@13797
   314
paulson@13797
   315
lemma increasingD: 
paulson@13805
   316
     "F \<in> increasing f ==> F \<in> stable {s. z \<subseteq> f s}"
paulson@13797
   317
paulson@13797
   318
by (unfold increasing_def, blast)
paulson@13797
   319
paulson@13805
   320
lemma increasing_constant [iff]: "F \<in> increasing (%s. c)"
paulson@13797
   321
by (unfold increasing_def stable_def, auto)
paulson@13797
   322
paulson@13797
   323
lemma mono_increasing_o: 
paulson@13805
   324
     "mono g ==> increasing f \<subseteq> increasing (g o f)"
paulson@13797
   325
apply (unfold increasing_def stable_def constrains_def, auto)
paulson@13797
   326
apply (blast intro: monoD order_trans)
paulson@13797
   327
done
paulson@13797
   328
paulson@13805
   329
(*Holds by the theorem (Suc m \<subseteq> n) = (m < n) *)
paulson@13797
   330
lemma strict_increasingD: 
paulson@13805
   331
     "!!z::nat. F \<in> increasing f ==> F \<in> stable {s. z < f s}"
paulson@13797
   332
by (simp add: increasing_def Suc_le_eq [symmetric])
paulson@13797
   333
paulson@13797
   334
paulson@13797
   335
(** The Elimination Theorem.  The "free" m has become universally quantified!
paulson@13805
   336
    Should the premise be !!m instead of \<forall>m ?  Would make it harder to use
paulson@13797
   337
    in forward proof. **)
paulson@13797
   338
paulson@13797
   339
lemma elimination: 
paulson@13805
   340
    "[| \<forall>m \<in> M. F \<in> {s. s x = m} co (B m) |]  
paulson@13805
   341
     ==> F \<in> {s. s x \<in> M} co (\<Union>m \<in> M. B m)"
paulson@13797
   342
by (unfold constrains_def, blast)
paulson@13797
   343
paulson@13797
   344
(*As above, but for the trivial case of a one-variable state, in which the
paulson@13797
   345
  state is identified with its one variable.*)
paulson@13797
   346
lemma elimination_sing: 
paulson@13805
   347
    "(\<forall>m \<in> M. F \<in> {m} co (B m)) ==> F \<in> M co (\<Union>m \<in> M. B m)"
paulson@13797
   348
by (unfold constrains_def, blast)
paulson@13797
   349
paulson@13797
   350
paulson@13797
   351
paulson@13797
   352
(*** Theoretical Results from Section 6 ***)
paulson@13797
   353
paulson@13797
   354
lemma constrains_strongest_rhs: 
paulson@13805
   355
    "F \<in> A co (strongest_rhs F A )"
paulson@13797
   356
by (unfold constrains_def strongest_rhs_def, blast)
paulson@13797
   357
paulson@13797
   358
lemma strongest_rhs_is_strongest: 
paulson@13805
   359
    "F \<in> A co B ==> strongest_rhs F A \<subseteq> B"
paulson@13797
   360
by (unfold constrains_def strongest_rhs_def, blast)
paulson@13797
   361
paulson@13797
   362
paulson@13797
   363
(** Ad-hoc set-theory rules **)
paulson@13797
   364
paulson@13805
   365
lemma Un_Diff_Diff [simp]: "A \<union> B - (A - B) = B"
paulson@13797
   366
by blast
paulson@13797
   367
paulson@13805
   368
lemma Int_Union_Union: "Union(B) \<inter> A = Union((%C. C \<inter> A)`B)"
paulson@13797
   369
by blast
paulson@13797
   370
paulson@13797
   371
(** Needed for WF reasoning in WFair.ML **)
paulson@13797
   372
paulson@13797
   373
lemma Image_less_than [simp]: "less_than `` {k} = greaterThan k"
paulson@13797
   374
by blast
paulson@13797
   375
paulson@13797
   376
lemma Image_inverse_less_than [simp]: "less_than^-1 `` {k} = lessThan k"
paulson@13797
   377
by blast
paulson@6536
   378
paulson@4776
   379
end