src/HOL/UNITY/PPROD.ML
author paulson
Mon May 17 10:38:08 1999 +0200 (1999-05-17)
changeset 6646 3ea726909fff
parent 6575 70d758762c50
child 6826 02c4dd469ec0
permissions -rw-r--r--
"component" now an infix
paulson@5899
     1
(*  Title:      HOL/UNITY/PPROD.ML
paulson@5899
     2
    ID:         $Id$
paulson@5899
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@5899
     4
    Copyright   1998  University of Cambridge
paulson@5899
     5
*)
paulson@5899
     6
paulson@6020
     7
paulson@6020
     8
val rinst = read_instantiate_sg (sign_of thy);
paulson@6020
     9
paulson@5899
    10
(**** PPROD ****)
paulson@5899
    11
paulson@5899
    12
(*** Basic properties ***)
paulson@5899
    13
paulson@6020
    14
Goalw [lift_set_def] "(f : lift_set i A) = (f i : A)";
paulson@6020
    15
by Auto_tac;
paulson@6020
    16
qed "lift_set_iff";
paulson@6020
    17
AddIffs [lift_set_iff];
paulson@6020
    18
paulson@6295
    19
Goalw [lift_act_def] "lift_act i Id = Id";
paulson@5899
    20
by Auto_tac;
paulson@6295
    21
qed "lift_act_Id";
paulson@6295
    22
Addsimps [lift_act_Id];
paulson@5899
    23
paulson@6299
    24
Goalw [lift_prog_def] "Init (lift_prog i F) = lift_set i (Init F)";
paulson@5972
    25
by Auto_tac;
paulson@5972
    26
qed "Init_lift_prog";
paulson@5972
    27
Addsimps [Init_lift_prog];
paulson@5972
    28
paulson@5972
    29
Goalw [lift_prog_def] "Acts (lift_prog i F) = lift_act i `` Acts F";
paulson@6295
    30
by (auto_tac (claset() addIs [Id_in_Acts RSN (2,image_eqI)], simpset()));
paulson@5972
    31
qed "Acts_lift_prog";
paulson@5972
    32
paulson@6020
    33
Goalw [PPROD_def] "Init (PPROD I F) = (INT i:I. lift_set i (Init (F i)))";
paulson@5972
    34
by Auto_tac;
paulson@5972
    35
qed "Init_PPROD";
paulson@5972
    36
Addsimps [Init_PPROD];
paulson@5972
    37
paulson@5899
    38
Goalw [lift_act_def]
paulson@5899
    39
    "((f,f') : lift_act i act) = (EX s'. f' = f(i := s') & (f i, s') : act)";
paulson@5899
    40
by (Blast_tac 1);
paulson@5899
    41
qed "lift_act_eq";
paulson@5899
    42
AddIffs [lift_act_eq];
paulson@5899
    43
paulson@6299
    44
Goal "Acts (PPROD I F) = insert Id (UN i:I. lift_act i `` Acts (F i))";
paulson@5899
    45
by (auto_tac (claset(),
paulson@5972
    46
	      simpset() addsimps [PPROD_def, Acts_lift_prog, Acts_JN]));
paulson@5899
    47
qed "Acts_PPROD";
paulson@5899
    48
paulson@5899
    49
Goal "PPROD {} F = SKIP";
paulson@5899
    50
by (simp_tac (simpset() addsimps [PPROD_def]) 1);
paulson@5899
    51
qed "PPROD_empty";
paulson@5899
    52
paulson@6299
    53
Goal "(PPI i: I. SKIP) = SKIP";
paulson@6299
    54
by (auto_tac (claset() addSIs [program_equalityI],
paulson@6299
    55
	      simpset() addsimps [Acts_lift_prog, SKIP_def, Acts_PPROD]));
paulson@6299
    56
qed "PPROD_SKIP";
paulson@6299
    57
paulson@5899
    58
Addsimps [PPROD_SKIP, PPROD_empty];
paulson@5899
    59
paulson@5972
    60
Goalw [PPROD_def]
paulson@5972
    61
    "PPROD (insert i I) F = (lift_prog i (F i)) Join (PPROD I F)";
paulson@5899
    62
by Auto_tac;
paulson@5899
    63
qed "PPROD_insert";
paulson@5899
    64
paulson@6646
    65
Goalw [PPROD_def] "i : I ==> (lift_prog i (F i)) component (PPROD I F)";
paulson@5972
    66
(*blast_tac doesn't use HO unification*)
paulson@5972
    67
by (fast_tac (claset() addIs [component_JN]) 1);
paulson@5972
    68
qed "component_PPROD";
paulson@5899
    69
paulson@5972
    70
paulson@6536
    71
(*** Safety: co, stable, invariant ***)
paulson@5972
    72
paulson@5972
    73
(** 1st formulation of lifting **)
paulson@5899
    74
paulson@6536
    75
Goal "(lift_prog i F : (lift_set i A) co (lift_set i B))  =  \
paulson@6536
    76
\     (F : A co B)";
paulson@5972
    77
by (auto_tac (claset(), 
paulson@5972
    78
	      simpset() addsimps [constrains_def, Acts_lift_prog]));
paulson@5972
    79
by (Blast_tac 2);
paulson@5972
    80
by (Force_tac 1);
paulson@5972
    81
qed "lift_prog_constrains_eq";
paulson@5972
    82
paulson@6020
    83
Goal "(lift_prog i F : stable (lift_set i A)) = (F : stable A)";
paulson@5972
    84
by (simp_tac (simpset() addsimps [stable_def, lift_prog_constrains_eq]) 1);
paulson@5972
    85
qed "lift_prog_stable_eq";
paulson@5972
    86
paulson@5972
    87
(*This one looks strange!  Proof probably is by case analysis on i=j.*)
paulson@6536
    88
Goal "F i : A co B  \
paulson@6536
    89
\     ==> lift_prog j (F j) : (lift_set i A) co (lift_set i B)";
paulson@5972
    90
by (auto_tac (claset(), 
paulson@5972
    91
	      simpset() addsimps [constrains_def, Acts_lift_prog]));
paulson@5972
    92
by (REPEAT (Blast_tac 1));
paulson@5972
    93
qed "constrains_imp_lift_prog_constrains";
paulson@5899
    94
paulson@5899
    95
Goal "i : I ==>  \
paulson@6536
    96
\     (PPROD I F : (lift_set i A) co (lift_set i B))  =  \
paulson@6536
    97
\     (F i : A co B)";
paulson@5972
    98
by (asm_simp_tac (simpset() addsimps [PPROD_def, constrains_JN]) 1);
paulson@5972
    99
by (blast_tac (claset() addIs [lift_prog_constrains_eq RS iffD1, 
paulson@5972
   100
			       constrains_imp_lift_prog_constrains]) 1);
paulson@5899
   101
qed "PPROD_constrains";
paulson@5899
   102
paulson@6020
   103
Goal "i : I ==> (PPROD I F : stable (lift_set i A)) = (F i : stable A)";
paulson@5972
   104
by (asm_simp_tac (simpset() addsimps [stable_def, PPROD_constrains]) 1);
paulson@5972
   105
qed "PPROD_stable";
paulson@5972
   106
paulson@5972
   107
paulson@5972
   108
(** 2nd formulation of lifting **)
paulson@5972
   109
paulson@6536
   110
Goal "[| lift_prog i F : AA co BB |] \
paulson@6536
   111
\     ==> F : (Applyall AA i) co (Applyall BB i)";
paulson@5899
   112
by (auto_tac (claset(), 
paulson@5899
   113
	      simpset() addsimps [Applyall_def, constrains_def, 
paulson@5972
   114
				  Acts_lift_prog]));
paulson@5972
   115
by (force_tac (claset() addSIs [rinst [("x", "?ff(i := ?u)")] image_eqI],
paulson@5899
   116
	       simpset()) 1);
paulson@5972
   117
qed "lift_prog_constrains_projection";
paulson@5972
   118
paulson@6536
   119
Goal "[| PPROD I F : AA co BB;  i: I |] \
paulson@6536
   120
\     ==> F i : (Applyall AA i) co (Applyall BB i)";
paulson@5972
   121
by (rtac lift_prog_constrains_projection 1);
paulson@5972
   122
(*rotate this assumption to be last*)
paulson@5972
   123
by (dres_inst_tac [("psi", "PPROD I F : ?C")] asm_rl 1);
paulson@5972
   124
by (asm_full_simp_tac (simpset() addsimps [PPROD_def, constrains_JN]) 1);
paulson@5899
   125
qed "PPROD_constrains_projection";
paulson@5899
   126
paulson@5899
   127
paulson@5972
   128
(** invariant **)
paulson@5972
   129
paulson@6451
   130
(*UNUSED*)
paulson@6451
   131
Goal "(lift_prog i F : invariant (lift_set i A)) = (F : invariant A)";
paulson@5972
   132
by (auto_tac (claset(),
paulson@5972
   133
	      simpset() addsimps [invariant_def, lift_prog_stable_eq]));
paulson@6451
   134
qed "lift_prog_invariant_eq";
paulson@5899
   135
paulson@6299
   136
Goal "[| F i : invariant A;  i : I |] \
paulson@6299
   137
\     ==> PPROD I F : invariant (lift_set i A)";
paulson@5972
   138
by (auto_tac (claset(),
paulson@5972
   139
	      simpset() addsimps [invariant_def, PPROD_stable]));
paulson@5972
   140
qed "invariant_imp_PPROD_invariant";
paulson@5972
   141
paulson@5972
   142
(*The f0 premise ensures that the product is well-defined.*)
paulson@6020
   143
Goal "[| PPROD I F : invariant (lift_set i A);  i : I;  \
paulson@5972
   144
\        f0: Init (PPROD I F) |] ==> F i : invariant A";
paulson@5899
   145
by (auto_tac (claset(),
paulson@5899
   146
	      simpset() addsimps [invariant_def, PPROD_stable]));
paulson@5972
   147
by (dres_inst_tac [("c", "f0(i:=x)")] subsetD 1);
paulson@5972
   148
by Auto_tac;
paulson@5972
   149
qed "PPROD_invariant_imp_invariant";
paulson@5972
   150
paulson@5972
   151
Goal "[| i : I;  f0: Init (PPROD I F) |] \
paulson@6020
   152
\     ==> (PPROD I F : invariant (lift_set i A)) = (F i : invariant A)";
paulson@5972
   153
by (blast_tac (claset() addIs [invariant_imp_PPROD_invariant, 
paulson@5972
   154
			       PPROD_invariant_imp_invariant]) 1);
paulson@5899
   155
qed "PPROD_invariant";
paulson@5899
   156
paulson@5972
   157
(*The f0 premise isn't needed if F is a constant program because then
paulson@5972
   158
  we get an initial state by replicating that of F*)
paulson@5972
   159
Goal "i : I \
paulson@6020
   160
\     ==> ((PPI x:I. F) : invariant (lift_set i A)) = (F : invariant A)";
paulson@5972
   161
by (auto_tac (claset(),
paulson@5972
   162
	      simpset() addsimps [invariant_def, PPROD_stable]));
paulson@5972
   163
qed "PFUN_invariant";
paulson@5972
   164
paulson@5899
   165
paulson@6536
   166
(*** Substitution Axiom versions: Co, Stable ***)
paulson@5899
   167
paulson@5972
   168
(** Reachability **)
paulson@5972
   169
paulson@5972
   170
Goal "[| f : reachable (PPROD I F);  i : I |] ==> f i : reachable (F i)";
paulson@5899
   171
by (etac reachable.induct 1);
paulson@5899
   172
by (auto_tac
paulson@5899
   173
    (claset() addIs reachable.intrs,
paulson@5899
   174
     simpset() addsimps [Acts_PPROD]));
paulson@5899
   175
qed "reachable_PPROD";
paulson@5899
   176
paulson@5972
   177
Goal "reachable (PPROD I F) <= {f. ALL i:I. f i : reachable (F i)}";
paulson@5899
   178
by (force_tac (claset() addSDs [reachable_PPROD], simpset()) 1);
paulson@5899
   179
qed "reachable_PPROD_subset1";
paulson@5899
   180
paulson@5972
   181
Goal "[| i ~: I;  A : reachable (F i) |]     \
paulson@5972
   182
\  ==> ALL f. f : reachable (PPROD I F)      \
paulson@5972
   183
\             --> f(i:=A) : reachable (lift_prog i (F i) Join PPROD I F)";
paulson@5899
   184
by (etac reachable.induct 1);
paulson@5899
   185
by (ALLGOALS Clarify_tac);
paulson@5899
   186
by (etac reachable.induct 1);
paulson@5899
   187
(*Init, Init case*)
paulson@5899
   188
by (force_tac (claset() addIs reachable.intrs,
paulson@5972
   189
	       simpset() addsimps [Acts_lift_prog]) 1);
paulson@5899
   190
(*Init of F, action of PPROD F case*)
paulson@5972
   191
by (rtac reachable.Acts 1);
paulson@5899
   192
by (force_tac (claset(), simpset() addsimps [Acts_Join]) 1);
paulson@5972
   193
by (assume_tac 1);
paulson@5899
   194
by (force_tac (claset() addIs [ext], simpset() addsimps [Acts_PPROD]) 1);
paulson@5899
   195
(*induction over the 2nd "reachable" assumption*)
paulson@5899
   196
by (eres_inst_tac [("xa","f")] reachable.induct 1);
paulson@5899
   197
(*Init of PPROD F, action of F case*)
paulson@5899
   198
by (res_inst_tac [("act","lift_act i act")] reachable.Acts 1);
paulson@5972
   199
by (force_tac (claset(), simpset() addsimps [Acts_lift_prog, Acts_Join]) 1);
paulson@5899
   200
by (force_tac (claset() addIs [reachable.Init], simpset()) 1);
paulson@5899
   201
by (force_tac (claset() addIs [ext], simpset() addsimps [lift_act_def]) 1);
paulson@5899
   202
(*last case: an action of PPROD I F*)
paulson@5972
   203
by (rtac reachable.Acts 1);
paulson@5899
   204
by (force_tac (claset(), simpset() addsimps [Acts_Join]) 1);
paulson@5972
   205
by (assume_tac 1);
paulson@5899
   206
by (force_tac (claset() addIs [ext], simpset() addsimps [Acts_PPROD]) 1);
paulson@5899
   207
qed_spec_mp "reachable_lift_Join_PPROD";
paulson@5899
   208
paulson@5899
   209
paulson@5899
   210
(*The index set must be finite: otherwise infinitely many copies of F can
paulson@5899
   211
  perform actions, and PPROD can never catch up in finite time.*)
paulson@5972
   212
Goal "finite I \
paulson@5972
   213
\     ==> {f. ALL i:I. f i : reachable (F i)} <= reachable (PPROD I F)";
paulson@5899
   214
by (etac finite_induct 1);
paulson@5899
   215
by (Simp_tac 1);
paulson@5899
   216
by (force_tac (claset() addDs [reachable_lift_Join_PPROD], 
paulson@5899
   217
	       simpset() addsimps [PPROD_insert]) 1);
paulson@5899
   218
qed "reachable_PPROD_subset2";
paulson@5899
   219
paulson@5972
   220
Goal "finite I ==> \
paulson@5972
   221
\     reachable (PPROD I F) = {f. ALL i:I. f i : reachable (F i)}";
paulson@5899
   222
by (REPEAT_FIRST (ares_tac [equalityI,
paulson@5899
   223
			    reachable_PPROD_subset1, 
paulson@5899
   224
			    reachable_PPROD_subset2]));
paulson@5899
   225
qed "reachable_PPROD_eq";
paulson@5899
   226
paulson@5899
   227
paulson@6536
   228
(** Co **)
paulson@5899
   229
paulson@6536
   230
Goal "[| F i : A Co B;  i: I;  finite I |]  \
paulson@6536
   231
\     ==> PPROD I F : (lift_set i A) Co (lift_set i B)";
paulson@5899
   232
by (auto_tac
paulson@5899
   233
    (claset(),
paulson@5899
   234
     simpset() addsimps [Constrains_def, Collect_conj_eq RS sym,
paulson@5899
   235
			 reachable_PPROD_eq]));
paulson@5899
   236
by (auto_tac (claset(), 
paulson@5972
   237
              simpset() addsimps [constrains_def, Acts_lift_prog, PPROD_def,
paulson@5899
   238
                                  Acts_JN]));
paulson@5899
   239
by (REPEAT (blast_tac (claset() addIs reachable.intrs) 1));
paulson@5972
   240
qed "Constrains_imp_PPROD_Constrains";
paulson@5972
   241
paulson@6299
   242
Goal "[| ALL i:I. f0 i : R i;   i: I |] \
paulson@6299
   243
\     ==> Applyall ({f. (ALL i:I. f i : R i)} Int lift_set i A) i = R i Int A";
paulson@6299
   244
by (force_tac (claset() addSIs [rinst [("x", "?ff(i := ?u)")] image_eqI],
paulson@6299
   245
	       simpset() addsimps [Applyall_def, lift_set_def]) 1);
paulson@5972
   246
qed "Applyall_Int_depend";
paulson@5972
   247
paulson@6575
   248
(*Again, we need the f0 premise so that PPROD I F has an initial state;
paulson@6575
   249
  otherwise its Co-property is vacuous.*)
paulson@6536
   250
Goal "[| PPROD I F : (lift_set i A) Co (lift_set i B);  \
paulson@5972
   251
\        i: I;  finite I;  f0: Init (PPROD I F) |]  \
paulson@6536
   252
\     ==> F i : A Co B";
paulson@6575
   253
by (full_simp_tac (simpset() addsimps [Constrains_eq_constrains]) 1);
paulson@5972
   254
by (subgoal_tac "ALL i:I. f0 i : reachable (F i)" 1);
paulson@5972
   255
by (blast_tac (claset() addIs [reachable.Init]) 2);
paulson@5972
   256
by (dtac PPROD_constrains_projection 1);
paulson@5972
   257
by (assume_tac 1);
paulson@5972
   258
by (asm_full_simp_tac
paulson@6299
   259
    (simpset() addsimps [Applyall_Int_depend, reachable_PPROD_eq]) 1);
paulson@5972
   260
qed "PPROD_Constrains_imp_Constrains";
paulson@5899
   261
paulson@5899
   262
paulson@5972
   263
Goal "[| i: I;  finite I;  f0: Init (PPROD I F) |]  \
paulson@6536
   264
\     ==> (PPROD I F : (lift_set i A) Co (lift_set i B)) =  \
paulson@6536
   265
\         (F i : A Co B)";
paulson@5972
   266
by (blast_tac (claset() addIs [Constrains_imp_PPROD_Constrains, 
paulson@5972
   267
			       PPROD_Constrains_imp_Constrains]) 1);
paulson@5972
   268
qed "PPROD_Constrains";
paulson@5972
   269
paulson@5972
   270
Goal "[| i: I;  finite I;  f0: Init (PPROD I F) |]  \
paulson@6020
   271
\     ==> (PPROD I F : Stable (lift_set i A)) = (F i : Stable A)";
paulson@5972
   272
by (asm_simp_tac (simpset() delsimps [Init_PPROD]
paulson@5972
   273
			    addsimps [Stable_def, PPROD_Constrains]) 1);
paulson@5899
   274
qed "PPROD_Stable";
paulson@5899
   275
paulson@5899
   276
paulson@5972
   277
(** PFUN (no dependence on i) doesn't require the f0 premise **)
paulson@5899
   278
paulson@6299
   279
Goal "i: I \
paulson@6299
   280
\     ==> Applyall ({f. (ALL i:I. f i : R)} Int lift_set i A) i = R Int A";
paulson@5972
   281
by (force_tac (claset(), simpset() addsimps [Applyall_def]) 1);
paulson@5972
   282
qed "Applyall_Int";
paulson@5972
   283
paulson@6536
   284
Goal "[| (PPI x:I. F) : (lift_set i A) Co (lift_set i B);  \
paulson@5972
   285
\        i: I;  finite I |]  \
paulson@6536
   286
\     ==> F : A Co B";
paulson@6575
   287
by (full_simp_tac (simpset() addsimps [Constrains_eq_constrains]) 1);
paulson@5972
   288
by (dtac PPROD_constrains_projection 1);
paulson@5972
   289
by (assume_tac 1);
paulson@5972
   290
by (asm_full_simp_tac
paulson@5972
   291
    (simpset() addsimps [Applyall_Int, Collect_conj_eq RS sym,
paulson@5972
   292
			 reachable_PPROD_eq]) 1);
paulson@5972
   293
qed "PFUN_Constrains_imp_Constrains";
paulson@5972
   294
paulson@5972
   295
Goal "[| i: I;  finite I |]  \
paulson@6536
   296
\     ==> ((PPI x:I. F) : (lift_set i A) Co (lift_set i B)) =  \
paulson@6536
   297
\         (F : A Co B)";
paulson@5972
   298
by (blast_tac (claset() addIs [Constrains_imp_PPROD_Constrains, 
paulson@5972
   299
			       PFUN_Constrains_imp_Constrains]) 1);
paulson@5972
   300
qed "PFUN_Constrains";
paulson@5972
   301
paulson@5972
   302
Goal "[| i: I;  finite I |]  \
paulson@6020
   303
\     ==> ((PPI x:I. F) : Stable (lift_set i A)) = (F : Stable A)";
paulson@5972
   304
by (asm_simp_tac (simpset() addsimps [Stable_def, PFUN_Constrains]) 1);
paulson@5972
   305
qed "PFUN_Stable";
paulson@5972
   306
paulson@5972
   307
paulson@5972
   308
paulson@5972
   309
(*** guarantees properties ***)
paulson@5972
   310
paulson@5972
   311
paulson@5972
   312
Goal "drop_act i (lift_act i act) = act";
paulson@5972
   313
by (force_tac (claset() addSIs [rinst [("x", "?ff(i := ?u)")] exI],
paulson@5972
   314
	       simpset() addsimps [drop_act_def, lift_act_def]) 1);
paulson@5972
   315
qed "lift_act_inverse";
paulson@5972
   316
Addsimps [lift_act_inverse];
paulson@5972
   317
paulson@5972
   318
paulson@5972
   319
Goal "(lift_prog i F) Join G = lift_prog i H \
paulson@5972
   320
\     ==> EX J. H = F Join J";
paulson@5972
   321
by (etac program_equalityE 1);
paulson@5972
   322
by (auto_tac (claset(), simpset() addsimps [Acts_lift_prog, Acts_Join]));
paulson@5972
   323
by (res_inst_tac [("x", 
paulson@5972
   324
		   "mk_program(Applyall(Init G) i, drop_act i `` Acts G)")] 
paulson@5972
   325
    exI 1);
paulson@5972
   326
by (rtac program_equalityI 1);
paulson@5972
   327
(*Init*)
paulson@5972
   328
by (simp_tac (simpset() addsimps [Applyall_def]) 1);
paulson@5972
   329
(*Blast_tac can't do HO unification, needed to invent function states*)
paulson@5972
   330
by (fast_tac (claset() addEs [equalityE]) 1);
paulson@5972
   331
(*Now for the Actions*)
paulson@5972
   332
by (dres_inst_tac [("f", "op `` (drop_act i)")] arg_cong 1);
paulson@5972
   333
by (asm_full_simp_tac 
paulson@5972
   334
    (simpset() addsimps [insert_absorb, Acts_Join,
paulson@5972
   335
			 image_Un, image_compose RS sym, o_def]) 1);
paulson@5972
   336
qed "lift_prog_Join_eq_lift_prog_D";
paulson@5972
   337
paulson@5972
   338
paulson@5972
   339
Goal "F : X guarantees Y \
paulson@5972
   340
\     ==> lift_prog i F : (lift_prog i `` X) guarantees (lift_prog i `` Y)";
paulson@5972
   341
by (rtac guaranteesI 1);
paulson@5972
   342
by Auto_tac;
paulson@5972
   343
by (blast_tac (claset() addDs [lift_prog_Join_eq_lift_prog_D, guaranteesD]) 1);
paulson@5972
   344
qed "lift_prog_guarantees";
paulson@5972
   345
paulson@5972
   346