src/HOL/UNITY/Union.ML
author paulson
Mon Oct 11 10:53:39 1999 +0200 (1999-10-11)
changeset 7826 c6a8b73b6c2a
parent 7689 affe0c2fdfbf
child 7878 43b03d412b82
permissions -rw-r--r--
working shapshot with "projecting" and "extending"
     1 (*  Title:      HOL/UNITY/Union.ML
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1998  University of Cambridge
     5 
     6 Unions of programs
     7 
     8 From Misra's Chapter 5: Asynchronous Compositions of Programs
     9 *)
    10 
    11 Addcongs [UN_cong, INT_cong];
    12 
    13 
    14 (** SKIP **)
    15 
    16 Goal "Init SKIP = UNIV";
    17 by (simp_tac (simpset() addsimps [SKIP_def]) 1);
    18 qed "Init_SKIP";
    19 
    20 Goal "Acts SKIP = {Id}";
    21 by (simp_tac (simpset() addsimps [SKIP_def]) 1);
    22 qed "Acts_SKIP";
    23 
    24 Addsimps [Init_SKIP, Acts_SKIP];
    25 
    26 Goal "reachable SKIP = UNIV";
    27 by (force_tac (claset() addEs [reachable.induct]
    28 			addIs reachable.intrs, simpset()) 1);
    29 qed "reachable_SKIP";
    30 
    31 Addsimps [reachable_SKIP];
    32 
    33 (** SKIP and safety properties **)
    34 
    35 Goalw [constrains_def] "(SKIP : A co B) = (A<=B)";
    36 by Auto_tac;
    37 qed "SKIP_in_constrains_iff";
    38 AddIffs [SKIP_in_constrains_iff];
    39 
    40 Goalw [Constrains_def] "(SKIP : A Co B) = (A<=B)";
    41 by Auto_tac;
    42 qed "SKIP_in_Constrains_iff";
    43 AddIffs [SKIP_in_Constrains_iff];
    44 
    45 Goalw [stable_def] "SKIP : stable A";
    46 by Auto_tac;
    47 qed "SKIP_in_stable";
    48 AddIffs [SKIP_in_stable, SKIP_in_stable RS stable_imp_Stable];
    49 
    50 
    51 (** Join **)
    52 
    53 Goal "Init (F Join G) = Init F Int Init G";
    54 by (simp_tac (simpset() addsimps [Join_def]) 1);
    55 qed "Init_Join";
    56 
    57 Goal "Acts (F Join G) = Acts F Un Acts G";
    58 by (auto_tac (claset(), simpset() addsimps [Join_def]));
    59 qed "Acts_Join";
    60 
    61 Addsimps [Init_Join, Acts_Join];
    62 
    63 
    64 (** JN **)
    65 
    66 Goalw [JOIN_def, SKIP_def] "(JN i:{}. F i) = SKIP";
    67 by Auto_tac;
    68 qed "JN_empty";
    69 Addsimps [JN_empty];
    70 
    71 Goal "(JN i:insert a I. F i) = (F a) Join (JN i:I. F i)";
    72 by (rtac program_equalityI 1);
    73 by (ALLGOALS (simp_tac (simpset() addsimps [JOIN_def, Join_def])));
    74 qed "JN_insert";
    75 Addsimps[JN_empty, JN_insert];
    76 
    77 Goal "Init (JN i:I. F i) = (INT i:I. Init (F i))";
    78 by (simp_tac (simpset() addsimps [JOIN_def]) 1);
    79 qed "Init_JN";
    80 
    81 Goal "Acts (JN i:I. F i) = insert Id (UN i:I. Acts (F i))";
    82 by (auto_tac (claset(), simpset() addsimps [JOIN_def]));
    83 qed "Acts_JN";
    84 
    85 Addsimps [Init_JN, Acts_JN];
    86 
    87 val prems = Goalw [JOIN_def]
    88     "[| I=J;  !!i. i:J ==> F i = G i |] ==> \
    89 \    (JN i:I. F i) = (JN i:J. G i)";
    90 by (asm_simp_tac (simpset() addsimps prems) 1);
    91 qed "JN_cong";
    92 
    93 Addcongs [JN_cong];
    94 
    95 
    96 (** Algebraic laws **)
    97 
    98 Goal "F Join G = G Join F";
    99 by (simp_tac (simpset() addsimps [Join_def, Un_commute, Int_commute]) 1);
   100 qed "Join_commute";
   101 
   102 Goal "A Join (B Join C) = B Join (A Join C)";
   103 by (simp_tac (simpset() addsimps Un_ac@Int_ac@[Join_def]) 1);
   104 qed "Join_left_commute";
   105 
   106 Goal "(F Join G) Join H = F Join (G Join H)";
   107 by (simp_tac (simpset() addsimps Un_ac@[Join_def, Int_assoc]) 1);
   108 qed "Join_assoc";
   109  
   110 Goalw [Join_def, SKIP_def] "SKIP Join F = F";
   111 by (rtac program_equalityI 1);
   112 by (ALLGOALS (simp_tac (simpset() addsimps [insert_absorb])));
   113 qed "Join_SKIP_left";
   114 
   115 Goalw [Join_def, SKIP_def] "F Join SKIP = F";
   116 by (rtac program_equalityI 1);
   117 by (ALLGOALS (simp_tac (simpset() addsimps [insert_absorb])));
   118 qed "Join_SKIP_right";
   119 
   120 Addsimps [Join_SKIP_left, Join_SKIP_right];
   121 
   122 Goalw [Join_def] "F Join F = F";
   123 by (rtac program_equalityI 1);
   124 by Auto_tac;
   125 qed "Join_absorb";
   126 
   127 Addsimps [Join_absorb];
   128 
   129 Goalw [Join_def] "A Join (A Join B) = A Join B";
   130 by (rtac program_equalityI 1);
   131 by Auto_tac;
   132 qed "Join_left_absorb";
   133 
   134 (*Join is an AC-operator*)
   135 val Join_ac = [Join_assoc, Join_left_absorb, Join_commute, Join_left_commute];
   136 
   137 
   138 (*** JN laws ***)
   139 
   140 (*Also follows by JN_insert and insert_absorb, but the proof is longer*)
   141 Goal "k:I ==> F k Join (JN i:I. F i) = (JN i:I. F i)";
   142 by (auto_tac (claset() addSIs [program_equalityI], simpset()));
   143 qed "JN_absorb";
   144 
   145 Goal "(JN i: I Un J. F i) = ((JN i: I. F i) Join (JN i:J. F i))";
   146 by (auto_tac (claset() addSIs [program_equalityI], simpset()));
   147 qed "JN_Un";
   148 
   149 Goal "(JN i:I. c) = (if I={} then SKIP else c)";
   150 by (auto_tac (claset() addSIs [program_equalityI], simpset()));
   151 qed "JN_constant";
   152 
   153 Goal "(JN i:I. F i Join G i) = (JN i:I. F i)  Join  (JN i:I. G i)";
   154 by (auto_tac (claset() addSIs [program_equalityI], simpset()));
   155 qed "JN_Join_distrib";
   156 
   157 Goal "i : I ==> (JN i:I. F i Join G) = ((JN i:I. F i) Join G)";
   158 by (asm_simp_tac (simpset() addsimps [JN_Join_distrib, JN_constant]) 1);
   159 by Auto_tac;
   160 qed "JN_Join_miniscope";
   161 
   162 
   163 (*** Safety: co, stable, FP ***)
   164 
   165 (*Fails if I={} because it collapses to SKIP : A co B*)
   166 Goalw [constrains_def, JOIN_def]
   167     "i : I ==> (JN i:I. F i) : A co B = (ALL i:I. F i : A co B)";
   168 by (Simp_tac 1);
   169 by (Blast_tac 1);
   170 qed "JN_constrains";
   171 
   172 Goal "(F Join G : A co B) = (F : A co B & G : A co B)";
   173 by (auto_tac
   174     (claset(),
   175      simpset() addsimps [constrains_def, Join_def]));
   176 qed "Join_constrains";
   177 
   178 (*Analogous weak versions FAIL; see Misra [1994] 5.4.1, Substitution Axiom.
   179   reachable (F Join G) could be much bigger than reachable F, reachable G
   180 *)
   181 
   182 
   183 Goal "[| F : A co A';  G : B co B' |] \
   184 \     ==> F Join G : (A Int B) co (A' Un B')";
   185 by (simp_tac (simpset() addsimps [Join_constrains]) 1);
   186 by (blast_tac (claset() addIs [constrains_weaken]) 1);
   187 qed "Join_constrains_weaken";
   188 
   189 Goal "[| ALL i:I. F i : A i co A' i;  i: I |] \
   190 \     ==> (JN i:I. F i) : (INT i:I. A i) co (UN i:I. A' i)";
   191 by (asm_simp_tac (simpset() addsimps [JN_constrains]) 1);
   192 by (blast_tac (claset() addIs [constrains_weaken]) 1);
   193 qed "JN_constrains_weaken";
   194 
   195 Goal "i : I ==> \
   196 \     (JN i:I. F i) : stable A = (ALL i:I. F i : stable A)";
   197 by (asm_simp_tac (simpset() addsimps [stable_def, JN_constrains]) 1);
   198 qed "JN_stable";
   199 
   200 Goal "[| ALL i:I. F i : invariant A;  i : I |]  \
   201 \      ==> (JN i:I. F i) : invariant A";
   202 by (asm_full_simp_tac (simpset() addsimps [invariant_def, JN_stable]) 1);
   203 by (Blast_tac 1);
   204 bind_thm ("invariant_JN_I", ballI RS result());
   205 
   206 Goal "(F Join G : stable A) = \
   207 \     (F : stable A & G : stable A)";
   208 by (simp_tac (simpset() addsimps [stable_def, Join_constrains]) 1);
   209 qed "Join_stable";
   210 
   211 Goal "(F Join G : increasing f) = \
   212 \     (F : increasing f & G : increasing f)";
   213 by (simp_tac (simpset() addsimps [increasing_def, Join_stable]) 1);
   214 by (Blast_tac 1);
   215 qed "Join_increasing";
   216 
   217 Goal "[| F : invariant A; G : invariant A |]  \
   218 \     ==> F Join G : invariant A";
   219 by (full_simp_tac (simpset() addsimps [invariant_def, Join_stable]) 1);
   220 by (Blast_tac 1);
   221 qed "invariant_JoinI";
   222 
   223 Goal "i : I ==> FP (JN i:I. F i) = (INT i:I. FP (F i))";
   224 by (asm_simp_tac (simpset() addsimps [FP_def, JN_stable, INTER_def]) 1);
   225 qed "FP_JN";
   226 
   227 
   228 (*** Progress: transient, ensures ***)
   229 
   230 Goal "i : I ==> \
   231 \   (JN i:I. F i) : transient A = (EX i:I. F i : transient A)";
   232 by (auto_tac (claset(),
   233 	      simpset() addsimps [transient_def, JOIN_def]));
   234 qed "JN_transient";
   235 
   236 Goal "F Join G : transient A = \
   237 \     (F : transient A | G : transient A)";
   238 by (auto_tac (claset(),
   239 	      simpset() addsimps [bex_Un, transient_def,
   240 				  Join_def]));
   241 qed "Join_transient";
   242 
   243 Goal "i : I ==> \
   244 \     (JN i:I. F i) : A ensures B = \
   245 \     ((ALL i:I. F i : (A-B) co (A Un B)) & \
   246 \      (EX i:I. F i : A ensures B))";
   247 by (auto_tac (claset(),
   248 	      simpset() addsimps [ensures_def, JN_constrains, JN_transient]));
   249 qed "JN_ensures";
   250 
   251 Goalw [ensures_def]
   252      "F Join G : A ensures B =     \
   253 \     (F : (A-B) co (A Un B) & G : (A-B) co (A Un B) & \
   254 \      (F : transient (A-B) | G : transient (A-B)))";
   255 by (auto_tac (claset(),
   256 	      simpset() addsimps [Join_constrains, Join_transient]));
   257 qed "Join_ensures";
   258 
   259 Goalw [stable_def, constrains_def, Join_def]
   260     "[| F : stable A;  G : A co A' |] \
   261 \    ==> F Join G : A co A'";
   262 by (asm_full_simp_tac (simpset() addsimps [ball_Un]) 1);
   263 by (Blast_tac 1);
   264 qed "stable_Join_constrains";
   265 
   266 (*Premise for G cannot use Always because  F: Stable A  is weaker than
   267   G : stable A *)
   268 Goal "[| F : stable A;  G : invariant A |] ==> F Join G : Always A";
   269 by (full_simp_tac (simpset() addsimps [Always_def, invariant_def, 
   270 				       Stable_eq_stable, Join_stable]) 1);
   271 by (force_tac(claset() addIs [stable_reachable, stable_Int],
   272 	      simpset()) 1);
   273 qed "stable_Join_Always";
   274 
   275 Goal "[| F : stable A;  G : A ensures B |] ==> F Join G : A ensures B";
   276 by (asm_simp_tac (simpset() addsimps [Join_ensures]) 1);
   277 by (asm_full_simp_tac (simpset() addsimps [stable_def, ensures_def]) 1);
   278 by (etac constrains_weaken 1);
   279 by Auto_tac;
   280 qed "stable_Join_ensures1";
   281 
   282 (*As above, but exchanging the roles of F and G*)
   283 Goal "[| F : A ensures B;  G : stable A |] ==> F Join G : A ensures B";
   284 by (stac Join_commute 1);
   285 by (blast_tac (claset() addIs [stable_Join_ensures1]) 1);
   286 qed "stable_Join_ensures2";
   287 
   288 
   289 (** Diff and localTo **)
   290 
   291 Goalw [Diff_def] "F Join (Diff G (Acts F)) = F Join G";
   292 by (rtac program_equalityI 1);
   293 by Auto_tac;
   294 qed "Join_Diff2";
   295 
   296 Goalw [Diff_def]
   297      "Diff (F Join G) (Acts H) = (Diff F (Acts H)) Join (Diff G (Acts H))";
   298 by (rtac program_equalityI 1);
   299 by Auto_tac;
   300 qed "Diff_Join_distrib";
   301 
   302 Goalw [Diff_def, constrains_def] "(Diff F (Acts F) : A co B) = (A <= B)";
   303 by Auto_tac;
   304 qed "Diff_self_constrains";
   305 
   306 Goalw [Diff_def, Disjoint_def] "Disjoint F (Diff G (Acts F))";
   307 by Auto_tac;
   308 qed "Diff_Disjoint";
   309 
   310 Goal "[| G : v localTo F;  Disjoint F G |] ==> G : stable {s. v s = z}";
   311 by (asm_full_simp_tac 
   312     (simpset() addsimps [localTo_def, Diff_def, Disjoint_def,
   313 			 stable_def, constrains_def]) 1);
   314 by (Blast_tac 1);
   315 qed "localTo_imp_stable";
   316 
   317 Goalw [localTo_def, stable_def, constrains_def]
   318      "v localTo F <= (f o v) localTo F";
   319 by (Clarify_tac 1);
   320 by (force_tac (claset() addSEs [allE, ballE], simpset()) 1);
   321 qed "localTo_imp_o_localTo";
   322 
   323 Goalw [localTo_def, stable_def, constrains_def]
   324      "(%s. x) localTo F = UNIV";
   325 by (Blast_tac 1);
   326 qed "triv_localTo_eq_UNIV";
   327 
   328 Goal "(F Join G : v localTo H) = (F : v localTo H  &  G : v localTo H)";
   329 by (asm_full_simp_tac 
   330     (simpset() addsimps [localTo_def, Diff_Join_distrib,
   331 			 stable_def, Join_constrains]) 1);
   332 by (Blast_tac 1);
   333 qed "Join_localTo";
   334 
   335 Goal "F : v localTo F";
   336 by (simp_tac 
   337     (simpset() addsimps [localTo_def, stable_def, Diff_self_constrains]) 1);
   338 qed "self_localTo";
   339 
   340 
   341 
   342 (*** Higher-level rules involving localTo and Join ***)
   343 
   344 Goal "[| F : {s. P (v s)} co {s. P' (v s)};  G : v localTo F |]  \
   345 \     ==> F Join G : {s. P (v s)} co {s. P' (v s)}";
   346 by (asm_simp_tac (simpset() addsimps [Join_constrains]) 1);
   347 by (auto_tac (claset(), 
   348 	      simpset() addsimps [localTo_def, stable_def, constrains_def,
   349 				  Diff_def]));
   350 by (case_tac "act: Acts F" 1);
   351 by (Blast_tac 1);
   352 by (dtac bspec 1 THEN rtac Id_in_Acts 1);
   353 by (subgoal_tac "v x = v xa" 1);
   354 by Auto_tac;
   355 qed "constrains_localTo_constrains";
   356 
   357 Goalw [localTo_def, stable_def, constrains_def, Diff_def]
   358      "[| G : v localTo F;  G : w localTo F |]  \
   359 \     ==> G : (%s. (v s, w s)) localTo F";
   360 by (Blast_tac 1);
   361 qed "localTo_pairfun";
   362 
   363 Goal "[| F : {s. P (v s) (w s)} co {s. P' (v s) (w s)};   \
   364 \        G : v localTo F;       \
   365 \        G : w localTo F |]               \
   366 \     ==> F Join G : {s. P (v s) (w s)} co {s. P' (v s) (w s)}";
   367 by (res_inst_tac [("A", "{s. (%(x,y). P x y) (v s, w s)}"),
   368 		  ("A'", "{s. (%(x,y). P' x y) (v s, w s)}")] 
   369     constrains_weaken 1);
   370 by (rtac (localTo_pairfun RSN (2, constrains_localTo_constrains)) 1);
   371 by Auto_tac;
   372 qed "constrains_localTo_constrains2";
   373 
   374 Goalw [stable_def]
   375      "[| F : stable {s. P (v s) (w s)};   \
   376 \        G : v localTo F;  G : w localTo F |]               \
   377 \     ==> F Join G : stable {s. P (v s) (w s)}";
   378 by (blast_tac (claset() addIs [constrains_localTo_constrains2]) 1);
   379 qed "stable_localTo_stable2";
   380 
   381 Goal "[| F : stable {s. v s <= w s};   \
   382 \        G : v localTo F;       \
   383 \        F Join G : Increasing w |]               \
   384 \     ==> F Join G : Stable {s. v s <= w s}";
   385 by (auto_tac (claset(), 
   386 	      simpset() addsimps [stable_def, Stable_def, Increasing_def, 
   387 		    Constrains_def, Join_constrains, all_conj_distrib]));
   388 by (blast_tac (claset() addIs [constrains_weaken]) 1);
   389 (*The G case remains; proved like constrains_localTo_constrains*)
   390 by (auto_tac (claset(), 
   391 	      simpset() addsimps [localTo_def, stable_def, constrains_def,
   392 				  Diff_def]));
   393 by (case_tac "act: Acts F" 1);
   394 by (Blast_tac 1);
   395 by (thin_tac "ALL act:Acts F. ?P act" 1);
   396 by (thin_tac "ALL z. ALL act:Acts F. ?P z act" 1);
   397 by (dres_inst_tac [("x", "v xa")] spec 1 THEN dtac bspec 1 THEN rtac DiffI 1);
   398 by (assume_tac 1);
   399 by (Blast_tac 1);
   400 by (subgoal_tac "v x = v xa" 1);
   401 by Auto_tac;
   402 qed "Increasing_localTo_Stable";