src/HOL/UNITY/Union.ML
author paulson
Mon, 16 Nov 1998 10:39:30 +0100
changeset 5867 1c4806b4bf43
parent 5804 8e0a4c4fd67b
child 5898 3e34e7aa7479
permissions -rw-r--r--
generalized JN_empty and added reachable_SKIP
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@5252
    11
paulson@5867
    12
(** SKIP **)
paulson@5867
    13
paulson@5648
    14
Goal "Init SKIP = UNIV";
paulson@5648
    15
by (simp_tac (simpset() addsimps [SKIP_def]) 1);
paulson@5611
    16
qed "Init_SKIP";
paulson@5611
    17
paulson@5648
    18
Goal "Acts SKIP = {Id}";
paulson@5648
    19
by (simp_tac (simpset() addsimps [SKIP_def]) 1);
paulson@5648
    20
qed "Acts_SKIP";
paulson@5648
    21
paulson@5648
    22
Addsimps [Init_SKIP, Acts_SKIP];
paulson@5648
    23
paulson@5867
    24
Goal "reachable SKIP = UNIV";
paulson@5867
    25
by (force_tac (claset() addIs reachable.intrs, simpset()) 1);
paulson@5867
    26
qed "reachable_SKIP";
paulson@5867
    27
paulson@5867
    28
Addsimps [reachable_SKIP];
paulson@5867
    29
paulson@5867
    30
paulson@5867
    31
(** Join and JN **)
paulson@5867
    32
paulson@5611
    33
Goal "Init (F Join G) = Init F Int Init G";
paulson@5313
    34
by (simp_tac (simpset() addsimps [Join_def]) 1);
paulson@5313
    35
qed "Init_Join";
paulson@5252
    36
paulson@5611
    37
Goal "Acts (F Join G) = Acts F Un Acts G";
paulson@5596
    38
by (auto_tac (claset(), simpset() addsimps [Join_def]));
paulson@5313
    39
qed "Acts_Join";
paulson@5252
    40
paulson@5611
    41
Goal "Init (JN i:I. F i) = (INT i:I. Init (F i))";
paulson@5313
    42
by (simp_tac (simpset() addsimps [JOIN_def]) 1);
paulson@5313
    43
qed "Init_JN";
paulson@5252
    44
paulson@5611
    45
Goal "Acts (JN i:I. F i) = insert Id (UN i:I. Acts (F i))";
paulson@5596
    46
by (auto_tac (claset(), simpset() addsimps [JOIN_def]));
paulson@5313
    47
qed "Acts_JN";
paulson@5252
    48
paulson@5313
    49
Addsimps [Init_Join, Init_JN];
paulson@5259
    50
paulson@5867
    51
Goalw [JOIN_def, SKIP_def] "(JN i:{}. F i) = SKIP";
paulson@5867
    52
by Auto_tac;
paulson@5867
    53
qed "JN_empty";
paulson@5867
    54
paulson@5611
    55
Goal "(JN x:insert a A. B x) = (B a) Join (JN x:A. B x)";
paulson@5611
    56
by (rtac program_equalityI 1);
paulson@5596
    57
by (ALLGOALS (simp_tac (simpset() addsimps [JOIN_def, Join_def])));
paulson@5584
    58
qed "JN_insert";
paulson@5867
    59
Addsimps[JN_empty, JN_insert];
paulson@5584
    60
paulson@5584
    61
paulson@5611
    62
(** Algebraic laws **)
paulson@5259
    63
paulson@5611
    64
Goal "F Join G = G Join F";
paulson@5313
    65
by (simp_tac (simpset() addsimps [Join_def, Un_commute, Int_commute]) 1);
paulson@5259
    66
qed "Join_commute";
paulson@5259
    67
paulson@5611
    68
Goal "(F Join G) Join H = F Join (G Join H)";
paulson@5596
    69
by (simp_tac (simpset() addsimps Un_ac@[Join_def, Int_assoc]) 1);
paulson@5259
    70
qed "Join_assoc";
paulson@5596
    71
 
paulson@5611
    72
Goalw [Join_def, SKIP_def] "SKIP Join F = F";
paulson@5611
    73
by (rtac program_equalityI 1);
paulson@5596
    74
by (ALLGOALS (simp_tac (simpset() addsimps [insert_absorb])));
paulson@5611
    75
qed "Join_SKIP_left";
paulson@5584
    76
paulson@5611
    77
Goalw [Join_def, SKIP_def] "F Join SKIP = F";
paulson@5611
    78
by (rtac program_equalityI 1);
paulson@5611
    79
by (ALLGOALS (simp_tac (simpset() addsimps [insert_absorb])));
paulson@5611
    80
qed "Join_SKIP_right";
paulson@5611
    81
paulson@5611
    82
Addsimps [Join_SKIP_left, Join_SKIP_right];
paulson@5611
    83
paulson@5611
    84
Goalw [Join_def] "F Join F = F";
paulson@5611
    85
by (rtac program_equalityI 1);
paulson@5313
    86
by Auto_tac;
paulson@5313
    87
qed "Join_absorb";
paulson@5313
    88
paulson@5611
    89
Addsimps [Join_absorb];
paulson@5313
    90
paulson@5584
    91
paulson@5584
    92
paulson@5584
    93
paulson@5313
    94
(*** Safety: constrains, stable, FP ***)
paulson@5313
    95
paulson@5313
    96
Goalw [constrains_def, JOIN_def]
paulson@5584
    97
    "I ~= {} ==> \
paulson@5648
    98
\    (JN i:I. F i) : constrains A B = (ALL i:I. F i : constrains A B)";
paulson@5596
    99
by (Simp_tac 1);
paulson@5596
   100
by (Blast_tac 1);
paulson@5313
   101
qed "constrains_JN";
paulson@5313
   102
paulson@5648
   103
Goal "F Join G : constrains A B =  \
paulson@5648
   104
\     (F : constrains A B & G : constrains A B)";
paulson@5620
   105
by (auto_tac
paulson@5620
   106
    (claset(),
paulson@5620
   107
     simpset() addsimps [constrains_def, Join_def]));
paulson@5620
   108
qed "constrains_Join";
paulson@5620
   109
paulson@5313
   110
(**FAILS, I think; see 5.4.1, Substitution Axiom.
paulson@5620
   111
   The problem is to relate reachable (F Join G) with 
paulson@5620
   112
   reachable F and reachable G
paulson@5620
   113
paulson@5313
   114
Goalw [Constrains_def]
paulson@5648
   115
    "(JN i:I. F i) : Constrains A B = (ALL i:I. F i : Constrains A B)";
paulson@5313
   116
by (simp_tac (simpset() addsimps [constrains_JN]) 1);
paulson@5313
   117
by (Blast_tac 1);
paulson@5313
   118
qed "Constrains_JN";
paulson@5313
   119
paulson@5648
   120
Goal "F Join G : Constrains A B = (Constrains F A B & Constrains G A B)";
paulson@5584
   121
by (auto_tac
paulson@5584
   122
    (claset(),
paulson@5620
   123
     simpset() addsimps [Constrains_def, constrains_Join]));
paulson@5620
   124
qed "Constrains_Join";
paulson@5620
   125
**)
paulson@5313
   126
paulson@5648
   127
Goal "[| F : constrains A A';  G : constrains B B' |] \
paulson@5648
   128
\     ==> F Join G : constrains (A Int B) (A' Un B')";
paulson@5313
   129
by (simp_tac (simpset() addsimps [constrains_Join]) 1);
paulson@5313
   130
by (blast_tac (claset() addIs [constrains_weaken]) 1);
paulson@5313
   131
qed "constrains_Join_weaken";
paulson@5313
   132
paulson@5584
   133
Goal "I ~= {} ==> \
paulson@5648
   134
\     (JN i:I. F i) : stable A = (ALL i:I. F i : stable A)";
paulson@5584
   135
by (asm_simp_tac (simpset() addsimps [stable_def, constrains_JN]) 1);
paulson@5313
   136
qed "stable_JN";
paulson@5313
   137
paulson@5648
   138
Goal "F Join G : stable A = \
paulson@5648
   139
\     (F : stable A & G : stable A)";
paulson@5313
   140
by (simp_tac (simpset() addsimps [stable_def, constrains_Join]) 1);
paulson@5313
   141
qed "stable_Join";
paulson@5313
   142
paulson@5648
   143
Goal "I ~= {} ==> FP (JN i:I. F i) = (INT i:I. FP (F i))";
paulson@5584
   144
by (asm_simp_tac (simpset() addsimps [FP_def, stable_JN, INTER_def]) 1);
paulson@5313
   145
qed "FP_JN";
paulson@5313
   146
paulson@5313
   147
paulson@5313
   148
(*** Progress: transient, ensures ***)
paulson@5313
   149
paulson@5584
   150
Goal "I ~= {} ==> \
paulson@5648
   151
\   (JN i:I. F i) : transient A = (EX i:I. F i : transient A)";
paulson@5584
   152
by (auto_tac (claset(),
paulson@5584
   153
	      simpset() addsimps [transient_def, JOIN_def]));
paulson@5313
   154
qed "transient_JN";
paulson@5313
   155
paulson@5648
   156
Goal "F Join G : transient A = \
paulson@5648
   157
\     (F : transient A | G : transient A)";
paulson@5584
   158
by (auto_tac (claset(),
paulson@5596
   159
	      simpset() addsimps [bex_Un, transient_def,
paulson@5584
   160
				  Join_def]));
paulson@5313
   161
qed "transient_Join";
paulson@5313
   162
paulson@5584
   163
Goal "I ~= {} ==> \
paulson@5648
   164
\     (JN i:I. F i) : ensures A B = \
paulson@5648
   165
\     ((ALL i:I. F i : constrains (A-B) (A Un B)) & \
paulson@5648
   166
\      (EX i:I. F i : ensures A B))";
paulson@5313
   167
by (auto_tac (claset(),
paulson@5584
   168
	      simpset() addsimps [ensures_def, constrains_JN, transient_JN]));
paulson@5313
   169
qed "ensures_JN";
paulson@5313
   170
paulson@5313
   171
Goalw [ensures_def]
paulson@5648
   172
     "F Join G : ensures A B =     \
paulson@5648
   173
\     (F : constrains (A-B) (A Un B) & \
paulson@5648
   174
\      G : constrains (A-B) (A Un B) & \
paulson@5648
   175
\      (F : ensures A B | G : ensures A B))";
paulson@5313
   176
by (auto_tac (claset(),
paulson@5313
   177
	      simpset() addsimps [constrains_Join, transient_Join]));
paulson@5313
   178
qed "ensures_Join";
paulson@5313
   179
paulson@5313
   180
Goalw [stable_def, constrains_def, Join_def]
paulson@5648
   181
    "[| F : stable A;  G : constrains A A' |] \
paulson@5648
   182
\    ==> F Join G : constrains A A'";
paulson@5648
   183
by (asm_full_simp_tac (simpset() addsimps [ball_Un]) 1);
paulson@5313
   184
by (Blast_tac 1);
paulson@5313
   185
qed "stable_constrains_Join";
paulson@5313
   186
paulson@5648
   187
(*Premise for G cannot use Invariant because  Stable F A  is weaker than
paulson@5648
   188
  G : stable A *)
paulson@5648
   189
Goal "[| F : stable A;  G : invariant A |] ==> F Join G : Invariant A";
paulson@5648
   190
by (full_simp_tac (simpset() addsimps [Invariant_def, invariant_def, 
paulson@5648
   191
				       Stable_eq_stable, stable_Join]) 1);
paulson@5313
   192
by (force_tac(claset() addIs [stable_reachable, stable_Int],
paulson@5313
   193
	      simpset() addsimps [Acts_Join]) 1);
paulson@5313
   194
qed "stable_Join_Invariant";
paulson@5313
   195
paulson@5648
   196
Goal "[| F : stable A;  G : ensures A B |] ==> F Join G : ensures A B";
paulson@5313
   197
by (asm_simp_tac (simpset() addsimps [ensures_Join]) 1);
paulson@5313
   198
by (asm_full_simp_tac (simpset() addsimps [stable_def, ensures_def]) 1);
paulson@5313
   199
by (etac constrains_weaken 1);
paulson@5313
   200
by Auto_tac;
paulson@5313
   201
qed "ensures_stable_Join1";
paulson@5313
   202
paulson@5313
   203
(*As above, but exchanging the roles of F and G*)
paulson@5648
   204
Goal "[| F : ensures A B;  G : stable A |] ==> F Join G : ensures A B";
paulson@5313
   205
by (stac Join_commute 1);
paulson@5313
   206
by (blast_tac (claset() addIs [ensures_stable_Join1]) 1);
paulson@5313
   207
qed "ensures_stable_Join2";
paulson@5313
   208
paulson@5648
   209
paulson@5804
   210
(** Diff and localTo **)
paulson@5648
   211
paulson@5804
   212
Goalw [Join_def, Diff_def] "F Join (Diff G (Acts F)) = F Join G";
paulson@5804
   213
by (rtac program_equalityI 1);
paulson@5804
   214
by Auto_tac;
paulson@5804
   215
qed "Join_Diff2";
paulson@5804
   216
paulson@5804
   217
Goalw [Diff_def, Disjoint_def] "Disjoint F (Diff G (Acts F))";
paulson@5804
   218
by Auto_tac;
paulson@5804
   219
qed "Diff_Disjoint";
paulson@5804
   220
paulson@5804
   221
Goal "[| F Join G : v localTo F;  Disjoint F G |] \
paulson@5804
   222
\     ==> G : (INT z. stable {s. v s = z})";
paulson@5648
   223
by (asm_full_simp_tac 
paulson@5804
   224
    (simpset() addsimps [localTo_def, Diff_def, Disjoint_def,
paulson@5804
   225
			 Acts_Join, stable_def, constrains_def]) 1);
paulson@5804
   226
by (Blast_tac 1);
paulson@5804
   227
qed "localTo_imp_stable";
paulson@5804
   228
paulson@5804
   229
Goal "[| F Join G : v localTo F;  (s,s') : act;  \
paulson@5804
   230
\        act : Acts G;  Disjoint F G |] ==> v s' = v s";
paulson@5804
   231
by (asm_full_simp_tac 
paulson@5804
   232
    (simpset() addsimps [localTo_def, Diff_def, Disjoint_def,
paulson@5804
   233
			 Acts_Join, stable_def, constrains_def]) 1);
paulson@5648
   234
by (Blast_tac 1);
paulson@5648
   235
qed "localTo_imp_equals";
paulson@5804
   236
paulson@5804
   237
Goalw [localTo_def, stable_def, constrains_def]
paulson@5804
   238
     "v localTo F <= (f o v) localTo F";
paulson@5804
   239
by (Clarify_tac 1);
paulson@5804
   240
by (auto_tac (claset() addSEs [allE, ballE], simpset()));
paulson@5804
   241
qed "localTo_imp_o_localTo";
paulson@5804
   242
paulson@5804
   243
paulson@5804
   244
(*** Higher-level rules involving localTo and Join ***)
paulson@5804
   245
paulson@5804
   246
Goal "[| F : constrains {s. P (v s) (w s)} {s. P' (v s) (w s)};   \
paulson@5804
   247
\        F Join G : v localTo F;       \
paulson@5804
   248
\        F Join G : w localTo F;       \
paulson@5804
   249
\        Disjoint F G |]               \
paulson@5804
   250
\     ==> F Join G : constrains {s. P (v s) (w s)} {s. P' (v s) (w s)}";
paulson@5804
   251
by (auto_tac (claset(), simpset() addsimps [constrains_def, Acts_Join]));
paulson@5804
   252
by (REPEAT_FIRST (dtac localTo_imp_equals THEN' REPEAT1 o atac));
paulson@5804
   253
by Auto_tac;
paulson@5804
   254
qed "constrains_localTo_constrains2";
paulson@5804
   255
paulson@5804
   256
Goalw [stable_def]
paulson@5804
   257
     "[| F : stable {s. P (v s) (w s)};   \
paulson@5804
   258
\        F Join G : v localTo F;       \
paulson@5804
   259
\        F Join G : w localTo F;       \
paulson@5804
   260
\        Disjoint F G |]               \
paulson@5804
   261
\     ==> F Join G : stable {s. P (v s) (w s)}";
paulson@5804
   262
by (blast_tac (claset() addIs [constrains_localTo_constrains2]) 1);
paulson@5804
   263
qed "stable_localTo_stable2";
paulson@5804
   264
paulson@5804
   265
paulson@5804
   266
Goal "(UN k. {s. f s = k}) = UNIV";
paulson@5804
   267
by (Blast_tac 1);
paulson@5804
   268
qed "UN_eq_UNIV";
paulson@5804
   269
paulson@5804
   270
Goal "[| F : stable {s. v s <= w s};   \
paulson@5804
   271
\        F Join G : v localTo F;       \
paulson@5804
   272
\        F Join G : Increasing w;      \
paulson@5804
   273
\        Disjoint F G |]               \
paulson@5804
   274
\     ==> F Join G : Stable {s. v s <= w s}";
paulson@5804
   275
by (safe_tac (claset() addSDs [localTo_imp_stable]));
paulson@5804
   276
by (rewrite_goals_tac [stable_def, Stable_def, Increasing_def]);
paulson@5804
   277
by (subgoal_tac "ALL k: UNIV. ?H : Constrains ({s. v s = k} Int ?AA) ?AA" 1);
paulson@5804
   278
by (dtac ball_Constrains_UN 1);
paulson@5804
   279
by (full_simp_tac (simpset() addsimps [UN_eq_UNIV]) 1);
paulson@5804
   280
by (rtac ballI 1);
paulson@5804
   281
by (subgoal_tac "F Join G : constrains ({s. v s = k} Int {s. v s <= w s}) \
paulson@5804
   282
\                                      ({s. v s = k} Un {s. v s <= w s})" 1);
paulson@5804
   283
by (asm_simp_tac (simpset() addsimps [constrains_Join]) 2);
paulson@5804
   284
by (blast_tac (claset() addIs [constrains_weaken]) 2);
paulson@5804
   285
by (dtac (constrains_imp_Constrains RS Constrains_Int) 1 THEN etac INT_D 1);
paulson@5804
   286
by (etac Constrains_weaken 2);
paulson@5804
   287
by Auto_tac;
paulson@5804
   288
qed "Increasing_localTo_Stable";