src/HOL/UNITY/UNITY.thy
author wenzelm
Thu Jul 23 22:13:42 2015 +0200 (2015-07-23)
changeset 60773 d09c66a0ea10
parent 58889 5b7a9633cfa8
child 61952 546958347e05
permissions -rw-r--r--
more symbols by default, without xsymbols mode;
     1 (*  Title:      HOL/UNITY/UNITY.thy
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Copyright   1998  University of Cambridge
     4 
     5 The basic UNITY theory (revised version, based upon the "co"
     6 operator).
     7 
     8 From Misra, "A Logic for Concurrent Programming", 1994.
     9 *)
    10 
    11 section {*The Basic UNITY Theory*}
    12 
    13 theory UNITY imports Main begin
    14 
    15 definition
    16   "Program =
    17     {(init:: 'a set, acts :: ('a * 'a)set set,
    18       allowed :: ('a * 'a)set set). Id \<in> acts & Id: allowed}"
    19 
    20 typedef 'a program = "Program :: ('a set * ('a * 'a) set set * ('a * 'a) set set) set"
    21   morphisms Rep_Program Abs_Program
    22   unfolding Program_def by blast
    23 
    24 definition Acts :: "'a program => ('a * 'a)set set" where
    25     "Acts F == (%(init, acts, allowed). acts) (Rep_Program F)"
    26 
    27 definition "constrains" :: "['a set, 'a set] => 'a program set"  (infixl "co"     60) where
    28     "A co B == {F. \<forall>act \<in> Acts F. act``A \<subseteq> B}"
    29 
    30 definition unless  :: "['a set, 'a set] => 'a program set"  (infixl "unless" 60)  where
    31     "A unless B == (A-B) co (A \<union> B)"
    32 
    33 definition mk_program :: "('a set * ('a * 'a)set set * ('a * 'a)set set)
    34                    => 'a program" where
    35     "mk_program == %(init, acts, allowed).
    36                       Abs_Program (init, insert Id acts, insert Id allowed)"
    37 
    38 definition Init :: "'a program => 'a set" where
    39     "Init F == (%(init, acts, allowed). init) (Rep_Program F)"
    40 
    41 definition AllowedActs :: "'a program => ('a * 'a)set set" where
    42     "AllowedActs F == (%(init, acts, allowed). allowed) (Rep_Program F)"
    43 
    44 definition Allowed :: "'a program => 'a program set" where
    45     "Allowed F == {G. Acts G \<subseteq> AllowedActs F}"
    46 
    47 definition stable     :: "'a set => 'a program set" where
    48     "stable A == A co A"
    49 
    50 definition strongest_rhs :: "['a program, 'a set] => 'a set" where
    51     "strongest_rhs F A == Inter {B. F \<in> A co B}"
    52 
    53 definition invariant :: "'a set => 'a program set" where
    54     "invariant A == {F. Init F \<subseteq> A} \<inter> stable A"
    55 
    56 definition increasing :: "['a => 'b::{order}] => 'a program set" where
    57     --{*Polymorphic in both states and the meaning of @{text "\<le>"}*}
    58     "increasing f == \<Inter>z. stable {s. z \<le> f s}"
    59 
    60 
    61 subsubsection{*The abstract type of programs*}
    62 
    63 lemmas program_typedef =
    64      Rep_Program Rep_Program_inverse Abs_Program_inverse 
    65      Program_def Init_def Acts_def AllowedActs_def mk_program_def
    66 
    67 lemma Id_in_Acts [iff]: "Id \<in> Acts F"
    68 apply (cut_tac x = F in Rep_Program)
    69 apply (auto simp add: program_typedef) 
    70 done
    71 
    72 lemma insert_Id_Acts [iff]: "insert Id (Acts F) = Acts F"
    73 by (simp add: insert_absorb)
    74 
    75 lemma Acts_nonempty [simp]: "Acts F \<noteq> {}"
    76 by auto
    77 
    78 lemma Id_in_AllowedActs [iff]: "Id \<in> AllowedActs F"
    79 apply (cut_tac x = F in Rep_Program)
    80 apply (auto simp add: program_typedef) 
    81 done
    82 
    83 lemma insert_Id_AllowedActs [iff]: "insert Id (AllowedActs F) = AllowedActs F"
    84 by (simp add: insert_absorb)
    85 
    86 subsubsection{*Inspectors for type "program"*}
    87 
    88 lemma Init_eq [simp]: "Init (mk_program (init,acts,allowed)) = init"
    89 by (simp add: program_typedef)
    90 
    91 lemma Acts_eq [simp]: "Acts (mk_program (init,acts,allowed)) = insert Id acts"
    92 by (simp add: program_typedef)
    93 
    94 lemma AllowedActs_eq [simp]:
    95      "AllowedActs (mk_program (init,acts,allowed)) = insert Id allowed"
    96 by (simp add: program_typedef)
    97 
    98 subsubsection{*Equality for UNITY programs*}
    99 
   100 lemma surjective_mk_program [simp]:
   101      "mk_program (Init F, Acts F, AllowedActs F) = F"
   102 apply (cut_tac x = F in Rep_Program)
   103 apply (auto simp add: program_typedef)
   104 apply (drule_tac f = Abs_Program in arg_cong)+
   105 apply (simp add: program_typedef insert_absorb)
   106 done
   107 
   108 lemma program_equalityI:
   109      "[| Init F = Init G; Acts F = Acts G; AllowedActs F = AllowedActs G |]  
   110       ==> F = G"
   111 apply (rule_tac t = F in surjective_mk_program [THEN subst])
   112 apply (rule_tac t = G in surjective_mk_program [THEN subst], simp)
   113 done
   114 
   115 lemma program_equalityE:
   116      "[| F = G;  
   117          [| Init F = Init G; Acts F = Acts G; AllowedActs F = AllowedActs G |] 
   118          ==> P |] ==> P"
   119 by simp 
   120 
   121 lemma program_equality_iff:
   122      "(F=G) =   
   123       (Init F = Init G & Acts F = Acts G &AllowedActs F = AllowedActs G)"
   124 by (blast intro: program_equalityI program_equalityE)
   125 
   126 
   127 subsubsection{*co*}
   128 
   129 lemma constrainsI: 
   130     "(!!act s s'. [| act: Acts F;  (s,s') \<in> act;  s \<in> A |] ==> s': A')  
   131      ==> F \<in> A co A'"
   132 by (simp add: constrains_def, blast)
   133 
   134 lemma constrainsD: 
   135     "[| F \<in> A co A'; act: Acts F;  (s,s'): act;  s \<in> A |] ==> s': A'"
   136 by (unfold constrains_def, blast)
   137 
   138 lemma constrains_empty [iff]: "F \<in> {} co B"
   139 by (unfold constrains_def, blast)
   140 
   141 lemma constrains_empty2 [iff]: "(F \<in> A co {}) = (A={})"
   142 by (unfold constrains_def, blast)
   143 
   144 lemma constrains_UNIV [iff]: "(F \<in> UNIV co B) = (B = UNIV)"
   145 by (unfold constrains_def, blast)
   146 
   147 lemma constrains_UNIV2 [iff]: "F \<in> A co UNIV"
   148 by (unfold constrains_def, blast)
   149 
   150 text{*monotonic in 2nd argument*}
   151 lemma constrains_weaken_R: 
   152     "[| F \<in> A co A'; A'<=B' |] ==> F \<in> A co B'"
   153 by (unfold constrains_def, blast)
   154 
   155 text{*anti-monotonic in 1st argument*}
   156 lemma constrains_weaken_L: 
   157     "[| F \<in> A co A'; B \<subseteq> A |] ==> F \<in> B co A'"
   158 by (unfold constrains_def, blast)
   159 
   160 lemma constrains_weaken: 
   161    "[| F \<in> A co A'; B \<subseteq> A; A'<=B' |] ==> F \<in> B co B'"
   162 by (unfold constrains_def, blast)
   163 
   164 subsubsection{*Union*}
   165 
   166 lemma constrains_Un: 
   167     "[| F \<in> A co A'; F \<in> B co B' |] ==> F \<in> (A \<union> B) co (A' \<union> B')"
   168 by (unfold constrains_def, blast)
   169 
   170 lemma constrains_UN: 
   171     "(!!i. i \<in> I ==> F \<in> (A i) co (A' i)) 
   172      ==> F \<in> (\<Union>i \<in> I. A i) co (\<Union>i \<in> I. A' i)"
   173 by (unfold constrains_def, blast)
   174 
   175 lemma constrains_Un_distrib: "(A \<union> B) co C = (A co C) \<inter> (B co C)"
   176 by (unfold constrains_def, blast)
   177 
   178 lemma constrains_UN_distrib: "(\<Union>i \<in> I. A i) co B = (\<Inter>i \<in> I. A i co B)"
   179 by (unfold constrains_def, blast)
   180 
   181 lemma constrains_Int_distrib: "C co (A \<inter> B) = (C co A) \<inter> (C co B)"
   182 by (unfold constrains_def, blast)
   183 
   184 lemma constrains_INT_distrib: "A co (\<Inter>i \<in> I. B i) = (\<Inter>i \<in> I. A co B i)"
   185 by (unfold constrains_def, blast)
   186 
   187 subsubsection{*Intersection*}
   188 
   189 lemma constrains_Int: 
   190     "[| F \<in> A co A'; F \<in> B co B' |] ==> F \<in> (A \<inter> B) co (A' \<inter> B')"
   191 by (unfold constrains_def, blast)
   192 
   193 lemma constrains_INT: 
   194     "(!!i. i \<in> I ==> F \<in> (A i) co (A' i)) 
   195      ==> F \<in> (\<Inter>i \<in> I. A i) co (\<Inter>i \<in> I. A' i)"
   196 by (unfold constrains_def, blast)
   197 
   198 lemma constrains_imp_subset: "F \<in> A co A' ==> A \<subseteq> A'"
   199 by (unfold constrains_def, auto)
   200 
   201 text{*The reasoning is by subsets since "co" refers to single actions
   202   only.  So this rule isn't that useful.*}
   203 lemma constrains_trans: 
   204     "[| F \<in> A co B; F \<in> B co C |] ==> F \<in> A co C"
   205 by (unfold constrains_def, blast)
   206 
   207 lemma constrains_cancel: 
   208    "[| F \<in> A co (A' \<union> B); F \<in> B co B' |] ==> F \<in> A co (A' \<union> B')"
   209 by (unfold constrains_def, clarify, blast)
   210 
   211 
   212 subsubsection{*unless*}
   213 
   214 lemma unlessI: "F \<in> (A-B) co (A \<union> B) ==> F \<in> A unless B"
   215 by (unfold unless_def, assumption)
   216 
   217 lemma unlessD: "F \<in> A unless B ==> F \<in> (A-B) co (A \<union> B)"
   218 by (unfold unless_def, assumption)
   219 
   220 
   221 subsubsection{*stable*}
   222 
   223 lemma stableI: "F \<in> A co A ==> F \<in> stable A"
   224 by (unfold stable_def, assumption)
   225 
   226 lemma stableD: "F \<in> stable A ==> F \<in> A co A"
   227 by (unfold stable_def, assumption)
   228 
   229 lemma stable_UNIV [simp]: "stable UNIV = UNIV"
   230 by (unfold stable_def constrains_def, auto)
   231 
   232 subsubsection{*Union*}
   233 
   234 lemma stable_Un: 
   235     "[| F \<in> stable A; F \<in> stable A' |] ==> F \<in> stable (A \<union> A')"
   236 
   237 apply (unfold stable_def)
   238 apply (blast intro: constrains_Un)
   239 done
   240 
   241 lemma stable_UN: 
   242     "(!!i. i \<in> I ==> F \<in> stable (A i)) ==> F \<in> stable (\<Union>i \<in> I. A i)"
   243 apply (unfold stable_def)
   244 apply (blast intro: constrains_UN)
   245 done
   246 
   247 lemma stable_Union: 
   248     "(!!A. A \<in> X ==> F \<in> stable A) ==> F \<in> stable (\<Union>X)"
   249 by (unfold stable_def constrains_def, blast)
   250 
   251 subsubsection{*Intersection*}
   252 
   253 lemma stable_Int: 
   254     "[| F \<in> stable A;  F \<in> stable A' |] ==> F \<in> stable (A \<inter> A')"
   255 apply (unfold stable_def)
   256 apply (blast intro: constrains_Int)
   257 done
   258 
   259 lemma stable_INT: 
   260     "(!!i. i \<in> I ==> F \<in> stable (A i)) ==> F \<in> stable (\<Inter>i \<in> I. A i)"
   261 apply (unfold stable_def)
   262 apply (blast intro: constrains_INT)
   263 done
   264 
   265 lemma stable_Inter: 
   266     "(!!A. A \<in> X ==> F \<in> stable A) ==> F \<in> stable (\<Inter>X)"
   267 by (unfold stable_def constrains_def, blast)
   268 
   269 lemma stable_constrains_Un: 
   270     "[| F \<in> stable C; F \<in> A co (C \<union> A') |] ==> F \<in> (C \<union> A) co (C \<union> A')"
   271 by (unfold stable_def constrains_def, blast)
   272 
   273 lemma stable_constrains_Int: 
   274   "[| F \<in> stable C; F \<in>  (C \<inter> A) co A' |] ==> F \<in> (C \<inter> A) co (C \<inter> A')"
   275 by (unfold stable_def constrains_def, blast)
   276 
   277 (*[| F \<in> stable C; F \<in>  (C \<inter> A) co A |] ==> F \<in> stable (C \<inter> A) *)
   278 lemmas stable_constrains_stable = stable_constrains_Int[THEN stableI]
   279 
   280 
   281 subsubsection{*invariant*}
   282 
   283 lemma invariantI: "[| Init F \<subseteq> A;  F \<in> stable A |] ==> F \<in> invariant A"
   284 by (simp add: invariant_def)
   285 
   286 text{*Could also say @{term "invariant A \<inter> invariant B \<subseteq> invariant(A \<inter> B)"}*}
   287 lemma invariant_Int:
   288      "[| F \<in> invariant A;  F \<in> invariant B |] ==> F \<in> invariant (A \<inter> B)"
   289 by (auto simp add: invariant_def stable_Int)
   290 
   291 
   292 subsubsection{*increasing*}
   293 
   294 lemma increasingD: 
   295      "F \<in> increasing f ==> F \<in> stable {s. z \<subseteq> f s}"
   296 by (unfold increasing_def, blast)
   297 
   298 lemma increasing_constant [iff]: "F \<in> increasing (%s. c)"
   299 by (unfold increasing_def stable_def, auto)
   300 
   301 lemma mono_increasing_o: 
   302      "mono g ==> increasing f \<subseteq> increasing (g o f)"
   303 apply (unfold increasing_def stable_def constrains_def, auto)
   304 apply (blast intro: monoD order_trans)
   305 done
   306 
   307 (*Holds by the theorem (Suc m \<subseteq> n) = (m < n) *)
   308 lemma strict_increasingD: 
   309      "!!z::nat. F \<in> increasing f ==> F \<in> stable {s. z < f s}"
   310 by (simp add: increasing_def Suc_le_eq [symmetric])
   311 
   312 
   313 (** The Elimination Theorem.  The "free" m has become universally quantified!
   314     Should the premise be !!m instead of \<forall>m ?  Would make it harder to use
   315     in forward proof. **)
   316 
   317 lemma elimination: 
   318     "[| \<forall>m \<in> M. F \<in> {s. s x = m} co (B m) |]  
   319      ==> F \<in> {s. s x \<in> M} co (\<Union>m \<in> M. B m)"
   320 by (unfold constrains_def, blast)
   321 
   322 text{*As above, but for the trivial case of a one-variable state, in which the
   323   state is identified with its one variable.*}
   324 lemma elimination_sing: 
   325     "(\<forall>m \<in> M. F \<in> {m} co (B m)) ==> F \<in> M co (\<Union>m \<in> M. B m)"
   326 by (unfold constrains_def, blast)
   327 
   328 
   329 
   330 subsubsection{*Theoretical Results from Section 6*}
   331 
   332 lemma constrains_strongest_rhs: 
   333     "F \<in> A co (strongest_rhs F A )"
   334 by (unfold constrains_def strongest_rhs_def, blast)
   335 
   336 lemma strongest_rhs_is_strongest: 
   337     "F \<in> A co B ==> strongest_rhs F A \<subseteq> B"
   338 by (unfold constrains_def strongest_rhs_def, blast)
   339 
   340 
   341 subsubsection{*Ad-hoc set-theory rules*}
   342 
   343 lemma Un_Diff_Diff [simp]: "A \<union> B - (A - B) = B"
   344 by blast
   345 
   346 lemma Int_Union_Union: "Union(B) \<inter> A = Union((%C. C \<inter> A)`B)"
   347 by blast
   348 
   349 text{*Needed for WF reasoning in WFair.thy*}
   350 
   351 lemma Image_less_than [simp]: "less_than `` {k} = greaterThan k"
   352 by blast
   353 
   354 lemma Image_inverse_less_than [simp]: "less_than^-1 `` {k} = lessThan k"
   355 by blast
   356 
   357 
   358 subsection{*Partial versus Total Transitions*}
   359 
   360 definition totalize_act :: "('a * 'a)set => ('a * 'a)set" where
   361     "totalize_act act == act \<union> Id_on (-(Domain act))"
   362 
   363 definition totalize :: "'a program => 'a program" where
   364     "totalize F == mk_program (Init F,
   365                                totalize_act ` Acts F,
   366                                AllowedActs F)"
   367 
   368 definition mk_total_program :: "('a set * ('a * 'a)set set * ('a * 'a)set set)
   369                    => 'a program" where
   370     "mk_total_program args == totalize (mk_program args)"
   371 
   372 definition all_total :: "'a program => bool" where
   373     "all_total F == \<forall>act \<in> Acts F. Domain act = UNIV"
   374   
   375 lemma insert_Id_image_Acts: "f Id = Id ==> insert Id (f`Acts F) = f ` Acts F"
   376 by (blast intro: sym [THEN image_eqI])
   377 
   378 
   379 subsubsection{*Basic properties*}
   380 
   381 lemma totalize_act_Id [simp]: "totalize_act Id = Id"
   382 by (simp add: totalize_act_def) 
   383 
   384 lemma Domain_totalize_act [simp]: "Domain (totalize_act act) = UNIV"
   385 by (auto simp add: totalize_act_def)
   386 
   387 lemma Init_totalize [simp]: "Init (totalize F) = Init F"
   388 by (unfold totalize_def, auto)
   389 
   390 lemma Acts_totalize [simp]: "Acts (totalize F) = (totalize_act ` Acts F)"
   391 by (simp add: totalize_def insert_Id_image_Acts) 
   392 
   393 lemma AllowedActs_totalize [simp]: "AllowedActs (totalize F) = AllowedActs F"
   394 by (simp add: totalize_def)
   395 
   396 lemma totalize_constrains_iff [simp]: "(totalize F \<in> A co B) = (F \<in> A co B)"
   397 by (simp add: totalize_def totalize_act_def constrains_def, blast)
   398 
   399 lemma totalize_stable_iff [simp]: "(totalize F \<in> stable A) = (F \<in> stable A)"
   400 by (simp add: stable_def)
   401 
   402 lemma totalize_invariant_iff [simp]:
   403      "(totalize F \<in> invariant A) = (F \<in> invariant A)"
   404 by (simp add: invariant_def)
   405 
   406 lemma all_total_totalize: "all_total (totalize F)"
   407 by (simp add: totalize_def all_total_def)
   408 
   409 lemma Domain_iff_totalize_act: "(Domain act = UNIV) = (totalize_act act = act)"
   410 by (force simp add: totalize_act_def)
   411 
   412 lemma all_total_imp_totalize: "all_total F ==> (totalize F = F)"
   413 apply (simp add: all_total_def totalize_def) 
   414 apply (rule program_equalityI)
   415   apply (simp_all add: Domain_iff_totalize_act image_def)
   416 done
   417 
   418 lemma all_total_iff_totalize: "all_total F = (totalize F = F)"
   419 apply (rule iffI) 
   420  apply (erule all_total_imp_totalize) 
   421 apply (erule subst) 
   422 apply (rule all_total_totalize) 
   423 done
   424 
   425 lemma mk_total_program_constrains_iff [simp]:
   426      "(mk_total_program args \<in> A co B) = (mk_program args \<in> A co B)"
   427 by (simp add: mk_total_program_def)
   428 
   429 
   430 subsection{*Rules for Lazy Definition Expansion*}
   431 
   432 text{*They avoid expanding the full program, which is a large expression*}
   433 
   434 lemma def_prg_Init:
   435      "F = mk_total_program (init,acts,allowed) ==> Init F = init"
   436 by (simp add: mk_total_program_def)
   437 
   438 lemma def_prg_Acts:
   439      "F = mk_total_program (init,acts,allowed) 
   440       ==> Acts F = insert Id (totalize_act ` acts)"
   441 by (simp add: mk_total_program_def)
   442 
   443 lemma def_prg_AllowedActs:
   444      "F = mk_total_program (init,acts,allowed)  
   445       ==> AllowedActs F = insert Id allowed"
   446 by (simp add: mk_total_program_def)
   447 
   448 text{*An action is expanded if a pair of states is being tested against it*}
   449 lemma def_act_simp:
   450      "act = {(s,s'). P s s'} ==> ((s,s') \<in> act) = P s s'"
   451 by (simp add: mk_total_program_def)
   452 
   453 text{*A set is expanded only if an element is being tested against it*}
   454 lemma def_set_simp: "A = B ==> (x \<in> A) = (x \<in> B)"
   455 by (simp add: mk_total_program_def)
   456 
   457 subsubsection{*Inspectors for type "program"*}
   458 
   459 lemma Init_total_eq [simp]:
   460      "Init (mk_total_program (init,acts,allowed)) = init"
   461 by (simp add: mk_total_program_def)
   462 
   463 lemma Acts_total_eq [simp]:
   464     "Acts(mk_total_program(init,acts,allowed)) = insert Id (totalize_act`acts)"
   465 by (simp add: mk_total_program_def)
   466 
   467 lemma AllowedActs_total_eq [simp]:
   468      "AllowedActs (mk_total_program (init,acts,allowed)) = insert Id allowed"
   469 by (auto simp add: mk_total_program_def)
   470 
   471 end