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