src/HOL/UNITY/Union.thy
author wenzelm
Mon Feb 08 21:28:27 2010 +0100 (2010-02-08)
changeset 35054 a5db9779b026
parent 32960 69916a850301
child 35068 544867142ea4
permissions -rw-r--r--
modernized some syntax translations;
     1 (*  Title:      HOL/UNITY/Union.thy
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Copyright   1998  University of Cambridge
     4 
     5 Partly from Misra's Chapter 5: Asynchronous Compositions of Programs.
     6 *)
     7 
     8 header{*Unions of Programs*}
     9 
    10 theory Union imports SubstAx FP begin
    11 
    12 constdefs
    13 
    14   (*FIXME: conjoin Init F \<inter> Init G \<noteq> {} *) 
    15   ok :: "['a program, 'a program] => bool"      (infixl "ok" 65)
    16     "F ok G == Acts F \<subseteq> AllowedActs G &
    17                Acts G \<subseteq> AllowedActs F"
    18 
    19   (*FIXME: conjoin (\<Inter>i \<in> I. Init (F i)) \<noteq> {} *) 
    20   OK  :: "['a set, 'a => 'b program] => bool"
    21     "OK I F == (\<forall>i \<in> I. \<forall>j \<in> I-{i}. Acts (F i) \<subseteq> AllowedActs (F j))"
    22 
    23   JOIN  :: "['a set, 'a => 'b program] => 'b program"
    24     "JOIN I F == mk_program (\<Inter>i \<in> I. Init (F i), \<Union>i \<in> I. Acts (F i),
    25                              \<Inter>i \<in> I. AllowedActs (F i))"
    26 
    27   Join :: "['a program, 'a program] => 'a program"      (infixl "Join" 65)
    28     "F Join G == mk_program (Init F \<inter> Init G, Acts F \<union> Acts G,
    29                              AllowedActs F \<inter> AllowedActs G)"
    30 
    31   SKIP :: "'a program"
    32     "SKIP == mk_program (UNIV, {}, UNIV)"
    33 
    34   (*Characterizes safety properties.  Used with specifying Allowed*)
    35   safety_prop :: "'a program set => bool"
    36     "safety_prop X == SKIP: X & (\<forall>G. Acts G \<subseteq> UNION X Acts --> G \<in> X)"
    37 
    38 syntax
    39   "_JOIN1"     :: "[pttrns, 'b set] => 'b set"         ("(3JN _./ _)" 10)
    40   "_JOIN"      :: "[pttrn, 'a set, 'b set] => 'b set"  ("(3JN _:_./ _)" 10)
    41 
    42 translations
    43   "JN x: A. B" == "CONST JOIN A (%x. B)"
    44   "JN x y. B" == "JN x. JN y. B"
    45   "JN x. B" == "JOIN CONST UNIV (%x. B)"
    46 
    47 syntax (xsymbols)
    48   SKIP     :: "'a program"                              ("\<bottom>")
    49   Join     :: "['a program, 'a program] => 'a program"  (infixl "\<squnion>" 65)
    50   "_JOIN1" :: "[pttrns, 'b set] => 'b set"              ("(3\<Squnion> _./ _)" 10)
    51   "_JOIN"  :: "[pttrn, 'a set, 'b set] => 'b set"       ("(3\<Squnion> _\<in>_./ _)" 10)
    52 
    53 
    54 subsection{*SKIP*}
    55 
    56 lemma Init_SKIP [simp]: "Init SKIP = UNIV"
    57 by (simp add: SKIP_def)
    58 
    59 lemma Acts_SKIP [simp]: "Acts SKIP = {Id}"
    60 by (simp add: SKIP_def)
    61 
    62 lemma AllowedActs_SKIP [simp]: "AllowedActs SKIP = UNIV"
    63 by (auto simp add: SKIP_def)
    64 
    65 lemma reachable_SKIP [simp]: "reachable SKIP = UNIV"
    66 by (force elim: reachable.induct intro: reachable.intros)
    67 
    68 subsection{*SKIP and safety properties*}
    69 
    70 lemma SKIP_in_constrains_iff [iff]: "(SKIP \<in> A co B) = (A \<subseteq> B)"
    71 by (unfold constrains_def, auto)
    72 
    73 lemma SKIP_in_Constrains_iff [iff]: "(SKIP \<in> A Co B) = (A \<subseteq> B)"
    74 by (unfold Constrains_def, auto)
    75 
    76 lemma SKIP_in_stable [iff]: "SKIP \<in> stable A"
    77 by (unfold stable_def, auto)
    78 
    79 declare SKIP_in_stable [THEN stable_imp_Stable, iff]
    80 
    81 
    82 subsection{*Join*}
    83 
    84 lemma Init_Join [simp]: "Init (F\<squnion>G) = Init F \<inter> Init G"
    85 by (simp add: Join_def)
    86 
    87 lemma Acts_Join [simp]: "Acts (F\<squnion>G) = Acts F \<union> Acts G"
    88 by (auto simp add: Join_def)
    89 
    90 lemma AllowedActs_Join [simp]:
    91      "AllowedActs (F\<squnion>G) = AllowedActs F \<inter> AllowedActs G"
    92 by (auto simp add: Join_def)
    93 
    94 
    95 subsection{*JN*}
    96 
    97 lemma JN_empty [simp]: "(\<Squnion>i\<in>{}. F i) = SKIP"
    98 by (unfold JOIN_def SKIP_def, auto)
    99 
   100 lemma JN_insert [simp]: "(\<Squnion>i \<in> insert a I. F i) = (F a)\<squnion>(\<Squnion>i \<in> I. F i)"
   101 apply (rule program_equalityI)
   102 apply (auto simp add: JOIN_def Join_def)
   103 done
   104 
   105 lemma Init_JN [simp]: "Init (\<Squnion>i \<in> I. F i) = (\<Inter>i \<in> I. Init (F i))"
   106 by (simp add: JOIN_def)
   107 
   108 lemma Acts_JN [simp]: "Acts (\<Squnion>i \<in> I. F i) = insert Id (\<Union>i \<in> I. Acts (F i))"
   109 by (auto simp add: JOIN_def)
   110 
   111 lemma AllowedActs_JN [simp]:
   112      "AllowedActs (\<Squnion>i \<in> I. F i) = (\<Inter>i \<in> I. AllowedActs (F i))"
   113 by (auto simp add: JOIN_def)
   114 
   115 
   116 lemma JN_cong [cong]: 
   117     "[| I=J;  !!i. i \<in> J ==> F i = G i |] ==> (\<Squnion>i \<in> I. F i) = (\<Squnion>i \<in> J. G i)"
   118 by (simp add: JOIN_def)
   119 
   120 
   121 subsection{*Algebraic laws*}
   122 
   123 lemma Join_commute: "F\<squnion>G = G\<squnion>F"
   124 by (simp add: Join_def Un_commute Int_commute)
   125 
   126 lemma Join_assoc: "(F\<squnion>G)\<squnion>H = F\<squnion>(G\<squnion>H)"
   127 by (simp add: Un_ac Join_def Int_assoc insert_absorb)
   128  
   129 lemma Join_left_commute: "A\<squnion>(B\<squnion>C) = B\<squnion>(A\<squnion>C)"
   130 by (simp add: Un_ac Int_ac Join_def insert_absorb)
   131 
   132 lemma Join_SKIP_left [simp]: "SKIP\<squnion>F = F"
   133 apply (unfold Join_def SKIP_def)
   134 apply (rule program_equalityI)
   135 apply (simp_all (no_asm) add: insert_absorb)
   136 done
   137 
   138 lemma Join_SKIP_right [simp]: "F\<squnion>SKIP = F"
   139 apply (unfold Join_def SKIP_def)
   140 apply (rule program_equalityI)
   141 apply (simp_all (no_asm) add: insert_absorb)
   142 done
   143 
   144 lemma Join_absorb [simp]: "F\<squnion>F = F"
   145 apply (unfold Join_def)
   146 apply (rule program_equalityI, auto)
   147 done
   148 
   149 lemma Join_left_absorb: "F\<squnion>(F\<squnion>G) = F\<squnion>G"
   150 apply (unfold Join_def)
   151 apply (rule program_equalityI, auto)
   152 done
   153 
   154 (*Join is an AC-operator*)
   155 lemmas Join_ac = Join_assoc Join_left_absorb Join_commute Join_left_commute
   156 
   157 
   158 subsection{*Laws Governing @{text "\<Squnion>"}*}
   159 
   160 (*Also follows by JN_insert and insert_absorb, but the proof is longer*)
   161 lemma JN_absorb: "k \<in> I ==> F k\<squnion>(\<Squnion>i \<in> I. F i) = (\<Squnion>i \<in> I. F i)"
   162 by (auto intro!: program_equalityI)
   163 
   164 lemma JN_Un: "(\<Squnion>i \<in> I \<union> J. F i) = ((\<Squnion>i \<in> I. F i)\<squnion>(\<Squnion>i \<in> J. F i))"
   165 by (auto intro!: program_equalityI)
   166 
   167 lemma JN_constant: "(\<Squnion>i \<in> I. c) = (if I={} then SKIP else c)"
   168 by (rule program_equalityI, auto)
   169 
   170 lemma JN_Join_distrib:
   171      "(\<Squnion>i \<in> I. F i\<squnion>G i) = (\<Squnion>i \<in> I. F i) \<squnion> (\<Squnion>i \<in> I. G i)"
   172 by (auto intro!: program_equalityI)
   173 
   174 lemma JN_Join_miniscope:
   175      "i \<in> I ==> (\<Squnion>i \<in> I. F i\<squnion>G) = ((\<Squnion>i \<in> I. F i)\<squnion>G)"
   176 by (auto simp add: JN_Join_distrib JN_constant)
   177 
   178 (*Used to prove guarantees_JN_I*)
   179 lemma JN_Join_diff: "i \<in> I ==> F i\<squnion>JOIN (I - {i}) F = JOIN I F"
   180 apply (unfold JOIN_def Join_def)
   181 apply (rule program_equalityI, auto)
   182 done
   183 
   184 
   185 subsection{*Safety: co, stable, FP*}
   186 
   187 (*Fails if I={} because it collapses to SKIP \<in> A co B, i.e. to A \<subseteq> B.  So an
   188   alternative precondition is A \<subseteq> B, but most proofs using this rule require
   189   I to be nonempty for other reasons anyway.*)
   190 lemma JN_constrains: 
   191     "i \<in> I ==> (\<Squnion>i \<in> I. F i) \<in> A co B = (\<forall>i \<in> I. F i \<in> A co B)"
   192 by (simp add: constrains_def JOIN_def, blast)
   193 
   194 lemma Join_constrains [simp]:
   195      "(F\<squnion>G \<in> A co B) = (F \<in> A co B & G \<in> A co B)"
   196 by (auto simp add: constrains_def Join_def)
   197 
   198 lemma Join_unless [simp]:
   199      "(F\<squnion>G \<in> A unless B) = (F \<in> A unless B & G \<in> A unless B)"
   200 by (simp add: Join_constrains unless_def)
   201 
   202 (*Analogous weak versions FAIL; see Misra [1994] 5.4.1, Substitution Axiom.
   203   reachable (F\<squnion>G) could be much bigger than reachable F, reachable G
   204 *)
   205 
   206 
   207 lemma Join_constrains_weaken:
   208      "[| F \<in> A co A';  G \<in> B co B' |]  
   209       ==> F\<squnion>G \<in> (A \<inter> B) co (A' \<union> B')"
   210 by (simp, blast intro: constrains_weaken)
   211 
   212 (*If I={}, it degenerates to SKIP \<in> UNIV co {}, which is false.*)
   213 lemma JN_constrains_weaken:
   214      "[| \<forall>i \<in> I. F i \<in> A i co A' i;  i \<in> I |]  
   215       ==> (\<Squnion>i \<in> I. F i) \<in> (\<Inter>i \<in> I. A i) co (\<Union>i \<in> I. A' i)"
   216 apply (simp (no_asm_simp) add: JN_constrains)
   217 apply (blast intro: constrains_weaken)
   218 done
   219 
   220 lemma JN_stable: "(\<Squnion>i \<in> I. F i) \<in> stable A = (\<forall>i \<in> I. F i \<in> stable A)"
   221 by (simp add: stable_def constrains_def JOIN_def)
   222 
   223 lemma invariant_JN_I:
   224      "[| !!i. i \<in> I ==> F i \<in> invariant A;  i \<in> I |]   
   225        ==> (\<Squnion>i \<in> I. F i) \<in> invariant A"
   226 by (simp add: invariant_def JN_stable, blast)
   227 
   228 lemma Join_stable [simp]:
   229      "(F\<squnion>G \<in> stable A) =  
   230       (F \<in> stable A & G \<in> stable A)"
   231 by (simp add: stable_def)
   232 
   233 lemma Join_increasing [simp]:
   234      "(F\<squnion>G \<in> increasing f) =  
   235       (F \<in> increasing f & G \<in> increasing f)"
   236 by (simp add: increasing_def Join_stable, blast)
   237 
   238 lemma invariant_JoinI:
   239      "[| F \<in> invariant A; G \<in> invariant A |]   
   240       ==> F\<squnion>G \<in> invariant A"
   241 by (simp add: invariant_def, blast)
   242 
   243 lemma FP_JN: "FP (\<Squnion>i \<in> I. F i) = (\<Inter>i \<in> I. FP (F i))"
   244 by (simp add: FP_def JN_stable INTER_def)
   245 
   246 
   247 subsection{*Progress: transient, ensures*}
   248 
   249 lemma JN_transient:
   250      "i \<in> I ==>  
   251     (\<Squnion>i \<in> I. F i) \<in> transient A = (\<exists>i \<in> I. F i \<in> transient A)"
   252 by (auto simp add: transient_def JOIN_def)
   253 
   254 lemma Join_transient [simp]:
   255      "F\<squnion>G \<in> transient A =  
   256       (F \<in> transient A | G \<in> transient A)"
   257 by (auto simp add: bex_Un transient_def Join_def)
   258 
   259 lemma Join_transient_I1: "F \<in> transient A ==> F\<squnion>G \<in> transient A"
   260 by (simp add: Join_transient)
   261 
   262 lemma Join_transient_I2: "G \<in> transient A ==> F\<squnion>G \<in> transient A"
   263 by (simp add: Join_transient)
   264 
   265 (*If I={} it degenerates to (SKIP \<in> A ensures B) = False, i.e. to ~(A \<subseteq> B) *)
   266 lemma JN_ensures:
   267      "i \<in> I ==>  
   268       (\<Squnion>i \<in> I. F i) \<in> A ensures B =  
   269       ((\<forall>i \<in> I. F i \<in> (A-B) co (A \<union> B)) & (\<exists>i \<in> I. F i \<in> A ensures B))"
   270 by (auto simp add: ensures_def JN_constrains JN_transient)
   271 
   272 lemma Join_ensures: 
   273      "F\<squnion>G \<in> A ensures B =      
   274       (F \<in> (A-B) co (A \<union> B) & G \<in> (A-B) co (A \<union> B) &  
   275        (F \<in> transient (A-B) | G \<in> transient (A-B)))"
   276 by (auto simp add: ensures_def Join_transient)
   277 
   278 lemma stable_Join_constrains: 
   279     "[| F \<in> stable A;  G \<in> A co A' |]  
   280      ==> F\<squnion>G \<in> A co A'"
   281 apply (unfold stable_def constrains_def Join_def)
   282 apply (simp add: ball_Un, blast)
   283 done
   284 
   285 (*Premise for G cannot use Always because  F \<in> Stable A  is weaker than
   286   G \<in> stable A *)
   287 lemma stable_Join_Always1:
   288      "[| F \<in> stable A;  G \<in> invariant A |] ==> F\<squnion>G \<in> Always A"
   289 apply (simp (no_asm_use) add: Always_def invariant_def Stable_eq_stable)
   290 apply (force intro: stable_Int)
   291 done
   292 
   293 (*As above, but exchanging the roles of F and G*)
   294 lemma stable_Join_Always2:
   295      "[| F \<in> invariant A;  G \<in> stable A |] ==> F\<squnion>G \<in> Always A"
   296 apply (subst Join_commute)
   297 apply (blast intro: stable_Join_Always1)
   298 done
   299 
   300 lemma stable_Join_ensures1:
   301      "[| F \<in> stable A;  G \<in> A ensures B |] ==> F\<squnion>G \<in> A ensures B"
   302 apply (simp (no_asm_simp) add: Join_ensures)
   303 apply (simp add: stable_def ensures_def)
   304 apply (erule constrains_weaken, auto)
   305 done
   306 
   307 (*As above, but exchanging the roles of F and G*)
   308 lemma stable_Join_ensures2:
   309      "[| F \<in> A ensures B;  G \<in> stable A |] ==> F\<squnion>G \<in> A ensures B"
   310 apply (subst Join_commute)
   311 apply (blast intro: stable_Join_ensures1)
   312 done
   313 
   314 
   315 subsection{*the ok and OK relations*}
   316 
   317 lemma ok_SKIP1 [iff]: "SKIP ok F"
   318 by (simp add: ok_def)
   319 
   320 lemma ok_SKIP2 [iff]: "F ok SKIP"
   321 by (simp add: ok_def)
   322 
   323 lemma ok_Join_commute:
   324      "(F ok G & (F\<squnion>G) ok H) = (G ok H & F ok (G\<squnion>H))"
   325 by (auto simp add: ok_def)
   326 
   327 lemma ok_commute: "(F ok G) = (G ok F)"
   328 by (auto simp add: ok_def)
   329 
   330 lemmas ok_sym = ok_commute [THEN iffD1, standard]
   331 
   332 lemma ok_iff_OK:
   333      "OK {(0::int,F),(1,G),(2,H)} snd = (F ok G & (F\<squnion>G) ok H)"
   334 apply (simp add: Ball_def conj_disj_distribR ok_def Join_def OK_def insert_absorb
   335               all_conj_distrib)
   336 apply blast
   337 done
   338 
   339 lemma ok_Join_iff1 [iff]: "F ok (G\<squnion>H) = (F ok G & F ok H)"
   340 by (auto simp add: ok_def)
   341 
   342 lemma ok_Join_iff2 [iff]: "(G\<squnion>H) ok F = (G ok F & H ok F)"
   343 by (auto simp add: ok_def)
   344 
   345 (*useful?  Not with the previous two around*)
   346 lemma ok_Join_commute_I: "[| F ok G; (F\<squnion>G) ok H |] ==> F ok (G\<squnion>H)"
   347 by (auto simp add: ok_def)
   348 
   349 lemma ok_JN_iff1 [iff]: "F ok (JOIN I G) = (\<forall>i \<in> I. F ok G i)"
   350 by (auto simp add: ok_def)
   351 
   352 lemma ok_JN_iff2 [iff]: "(JOIN I G) ok F =  (\<forall>i \<in> I. G i ok F)"
   353 by (auto simp add: ok_def)
   354 
   355 lemma OK_iff_ok: "OK I F = (\<forall>i \<in> I. \<forall>j \<in> I-{i}. (F i) ok (F j))"
   356 by (auto simp add: ok_def OK_def)
   357 
   358 lemma OK_imp_ok: "[| OK I F; i \<in> I; j \<in> I; i \<noteq> j|] ==> (F i) ok (F j)"
   359 by (auto simp add: OK_iff_ok)
   360 
   361 
   362 subsection{*Allowed*}
   363 
   364 lemma Allowed_SKIP [simp]: "Allowed SKIP = UNIV"
   365 by (auto simp add: Allowed_def)
   366 
   367 lemma Allowed_Join [simp]: "Allowed (F\<squnion>G) = Allowed F \<inter> Allowed G"
   368 by (auto simp add: Allowed_def)
   369 
   370 lemma Allowed_JN [simp]: "Allowed (JOIN I F) = (\<Inter>i \<in> I. Allowed (F i))"
   371 by (auto simp add: Allowed_def)
   372 
   373 lemma ok_iff_Allowed: "F ok G = (F \<in> Allowed G & G \<in> Allowed F)"
   374 by (simp add: ok_def Allowed_def)
   375 
   376 lemma OK_iff_Allowed: "OK I F = (\<forall>i \<in> I. \<forall>j \<in> I-{i}. F i \<in> Allowed(F j))"
   377 by (auto simp add: OK_iff_ok ok_iff_Allowed)
   378 
   379 subsection{*@{term safety_prop}, for reasoning about
   380  given instances of "ok"*}
   381 
   382 lemma safety_prop_Acts_iff:
   383      "safety_prop X ==> (Acts G \<subseteq> insert Id (UNION X Acts)) = (G \<in> X)"
   384 by (auto simp add: safety_prop_def)
   385 
   386 lemma safety_prop_AllowedActs_iff_Allowed:
   387      "safety_prop X ==> (UNION X Acts \<subseteq> AllowedActs F) = (X \<subseteq> Allowed F)"
   388 by (auto simp add: Allowed_def safety_prop_Acts_iff [symmetric])
   389 
   390 lemma Allowed_eq:
   391      "safety_prop X ==> Allowed (mk_program (init, acts, UNION X Acts)) = X"
   392 by (simp add: Allowed_def safety_prop_Acts_iff)
   393 
   394 (*For safety_prop to hold, the property must be satisfiable!*)
   395 lemma safety_prop_constrains [iff]: "safety_prop (A co B) = (A \<subseteq> B)"
   396 by (simp add: safety_prop_def constrains_def, blast)
   397 
   398 lemma safety_prop_stable [iff]: "safety_prop (stable A)"
   399 by (simp add: stable_def)
   400 
   401 lemma safety_prop_Int [simp]:
   402      "[| safety_prop X; safety_prop Y |] ==> safety_prop (X \<inter> Y)"
   403 by (simp add: safety_prop_def, blast)
   404 
   405 lemma safety_prop_INTER1 [simp]:
   406      "(!!i. safety_prop (X i)) ==> safety_prop (\<Inter>i. X i)"
   407 by (auto simp add: safety_prop_def, blast)
   408 
   409 lemma safety_prop_INTER [simp]:
   410      "(!!i. i \<in> I ==> safety_prop (X i)) ==> safety_prop (\<Inter>i \<in> I. X i)"
   411 by (auto simp add: safety_prop_def, blast)
   412 
   413 lemma def_prg_Allowed:
   414      "[| F == mk_program (init, acts, UNION X Acts) ; safety_prop X |]  
   415       ==> Allowed F = X"
   416 by (simp add: Allowed_eq)
   417 
   418 lemma Allowed_totalize [simp]: "Allowed (totalize F) = Allowed F"
   419 by (simp add: Allowed_def) 
   420 
   421 lemma def_total_prg_Allowed:
   422      "[| F == mk_total_program (init, acts, UNION X Acts) ; safety_prop X |]  
   423       ==> Allowed F = X"
   424 by (simp add: mk_total_program_def def_prg_Allowed) 
   425 
   426 lemma def_UNION_ok_iff:
   427      "[| F == mk_program(init,acts,UNION X Acts); safety_prop X |]  
   428       ==> F ok G = (G \<in> X & acts \<subseteq> AllowedActs G)"
   429 by (auto simp add: ok_def safety_prop_Acts_iff)
   430 
   431 text{*The union of two total programs is total.*}
   432 lemma totalize_Join: "totalize F\<squnion>totalize G = totalize (F\<squnion>G)"
   433 by (simp add: program_equalityI totalize_def Join_def image_Un)
   434 
   435 lemma all_total_Join: "[|all_total F; all_total G|] ==> all_total (F\<squnion>G)"
   436 by (simp add: all_total_def, blast)
   437 
   438 lemma totalize_JN: "(\<Squnion>i \<in> I. totalize (F i)) = totalize(\<Squnion>i \<in> I. F i)"
   439 by (simp add: program_equalityI totalize_def JOIN_def image_UN)
   440 
   441 lemma all_total_JN: "(!!i. i\<in>I ==> all_total (F i)) ==> all_total(\<Squnion>i\<in>I. F i)"
   442 by (simp add: all_total_iff_totalize totalize_JN [symmetric])
   443 
   444 end