src/HOL/UNITY/UNITY.ML
author paulson
Mon Oct 11 10:53:39 1999 +0200 (1999-10-11)
changeset 7826 c6a8b73b6c2a
parent 7630 d0e4a6f1f05c
child 7915 c7fd7eb3b0ef
permissions -rw-r--r--
working shapshot with "projecting" and "extending"
paulson@4776
     1
(*  Title:      HOL/UNITY/UNITY
paulson@4776
     2
    ID:         $Id$
paulson@4776
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@4776
     4
    Copyright   1998  University of Cambridge
paulson@4776
     5
paulson@4776
     6
The basic UNITY theory (revised version, based upon the "co" operator)
paulson@4776
     7
paulson@4776
     8
From Misra, "A Logic for Concurrent Programming", 1994
paulson@4776
     9
*)
paulson@4776
    10
paulson@4776
    11
set proof_timing;
paulson@4776
    12
paulson@4776
    13
paulson@6012
    14
(*** General lemmas ***)
paulson@6012
    15
paulson@6012
    16
Goal "UNIV Times UNIV = UNIV";
paulson@6012
    17
by Auto_tac;
paulson@6012
    18
qed "UNIV_Times_UNIV"; 
paulson@6012
    19
Addsimps [UNIV_Times_UNIV];
paulson@6012
    20
paulson@6012
    21
Goal "- (UNIV Times A) = UNIV Times (-A)";
paulson@6012
    22
by Auto_tac;
paulson@6012
    23
qed "Compl_Times_UNIV1"; 
paulson@6012
    24
paulson@6012
    25
Goal "- (A Times UNIV) = (-A) Times UNIV";
paulson@6012
    26
by Auto_tac;
paulson@6012
    27
qed "Compl_Times_UNIV2"; 
paulson@6012
    28
paulson@6012
    29
Addsimps [Compl_Times_UNIV1, Compl_Times_UNIV2]; 
paulson@6012
    30
paulson@6012
    31
paulson@6535
    32
(*** The abstract type of programs ***)
paulson@6535
    33
paulson@6535
    34
val rep_ss = simpset() addsimps 
paulson@6535
    35
                [Init_def, Acts_def, mk_program_def, Program_def, Rep_Program, 
paulson@6535
    36
		 Rep_Program_inverse, Abs_Program_inverse];
paulson@6535
    37
paulson@6535
    38
paulson@6535
    39
Goal "Id : Acts F";
paulson@6535
    40
by (cut_inst_tac [("x", "F")] Rep_Program 1);
paulson@6535
    41
by (auto_tac (claset(), rep_ss));
paulson@6535
    42
qed "Id_in_Acts";
paulson@6535
    43
AddIffs [Id_in_Acts];
paulson@6535
    44
paulson@6535
    45
Goal "insert Id (Acts F) = Acts F";
paulson@6535
    46
by (simp_tac (simpset() addsimps [insert_absorb, Id_in_Acts]) 1);
paulson@6535
    47
qed "insert_Id_Acts";
paulson@6535
    48
AddIffs [insert_Id_Acts];
paulson@6535
    49
paulson@6535
    50
(** Inspectors for type "program" **)
paulson@6535
    51
paulson@6535
    52
Goal "Init (mk_program (init,acts)) = init";
paulson@6535
    53
by (auto_tac (claset(), rep_ss));
paulson@6535
    54
qed "Init_eq";
paulson@6535
    55
paulson@6535
    56
Goal "Acts (mk_program (init,acts)) = insert Id acts";
paulson@6535
    57
by (auto_tac (claset(), rep_ss));
paulson@6535
    58
qed "Acts_eq";
paulson@6535
    59
paulson@6535
    60
Addsimps [Acts_eq, Init_eq];
paulson@6535
    61
paulson@6535
    62
paulson@6535
    63
(** The notation of equality for type "program" **)
paulson@6535
    64
paulson@6535
    65
Goal "[| Init F = Init G; Acts F = Acts G |] ==> F = G";
paulson@6535
    66
by (subgoals_tac ["EX x. Rep_Program F = x",
paulson@6535
    67
		  "EX x. Rep_Program G = x"] 1);
paulson@6535
    68
by (REPEAT (Blast_tac 2));
paulson@6535
    69
by (Clarify_tac 1);
paulson@6535
    70
by (auto_tac (claset(), rep_ss));
paulson@6535
    71
by (REPEAT (dres_inst_tac [("f", "Abs_Program")] arg_cong 1));
paulson@6535
    72
by (asm_full_simp_tac rep_ss 1);
paulson@6535
    73
qed "program_equalityI";
paulson@6535
    74
paulson@6535
    75
val [major,minor] =
paulson@6535
    76
Goal "[| F = G; [| Init F = Init G; Acts F = Acts G |] ==> P |] ==> P";
paulson@6535
    77
by (rtac minor 1);
paulson@6535
    78
by (auto_tac (claset(), simpset() addsimps [major]));
paulson@6535
    79
qed "program_equalityE";
paulson@6535
    80
paulson@6535
    81
paulson@6535
    82
(*** These rules allow "lazy" definition expansion 
paulson@6535
    83
     They avoid expanding the full program, which is a large expression
paulson@6535
    84
***)
paulson@6535
    85
paulson@6535
    86
Goal "F == mk_program (init,acts) ==> Init F = init";
paulson@6535
    87
by Auto_tac;
paulson@6535
    88
qed "def_prg_Init";
paulson@6535
    89
paulson@6535
    90
(*The program is not expanded, but its Init and Acts are*)
paulson@6535
    91
val [rew] = goal thy
paulson@6535
    92
    "[| F == mk_program (init,acts) |] \
paulson@6535
    93
\    ==> Init F = init & Acts F = insert Id acts";
paulson@6535
    94
by (rewtac rew);
paulson@6535
    95
by Auto_tac;
paulson@6535
    96
qed "def_prg_simps";
paulson@6535
    97
paulson@6535
    98
(*An action is expanded only if a pair of states is being tested against it*)
paulson@6535
    99
Goal "[| act == {(s,s'). P s s'} |] ==> ((s,s') : act) = P s s'";
paulson@6535
   100
by Auto_tac;
paulson@6535
   101
qed "def_act_simp";
paulson@6535
   102
paulson@6535
   103
fun simp_of_act def = def RS def_act_simp;
paulson@6535
   104
paulson@6535
   105
(*A set is expanded only if an element is being tested against it*)
paulson@6535
   106
Goal "A == B ==> (x : A) = (x : B)";
paulson@6535
   107
by Auto_tac;
paulson@6535
   108
qed "def_set_simp";
paulson@6535
   109
paulson@6535
   110
fun simp_of_set def = def RS def_set_simp;
paulson@6535
   111
paulson@6535
   112
paulson@6536
   113
(*** co ***)
paulson@4776
   114
paulson@7403
   115
(*These operators are not overloaded, but their operands are sets, and 
paulson@7403
   116
  ultimately there's a risk of reaching equality, which IS overloaded*)
paulson@7403
   117
overload_1st_set "UNITY.constrains";
paulson@5648
   118
overload_1st_set "UNITY.stable";
paulson@5648
   119
overload_1st_set "UNITY.unless";
paulson@5340
   120
paulson@5277
   121
val prems = Goalw [constrains_def]
paulson@5648
   122
    "(!!act s s'. [| act: Acts F;  (s,s') : act;  s: A |] ==> s': A') \
paulson@6536
   123
\    ==> F : A co A'";
paulson@4776
   124
by (blast_tac (claset() addIs prems) 1);
paulson@4776
   125
qed "constrainsI";
paulson@4776
   126
wenzelm@5069
   127
Goalw [constrains_def]
paulson@6536
   128
    "[| F : A co A'; act: Acts F;  (s,s'): act;  s: A |] ==> s': A'";
paulson@4776
   129
by (Blast_tac 1);
paulson@4776
   130
qed "constrainsD";
paulson@4776
   131
paulson@6536
   132
Goalw [constrains_def] "F : {} co B";
paulson@4776
   133
by (Blast_tac 1);
paulson@4776
   134
qed "constrains_empty";
paulson@4776
   135
paulson@7826
   136
Goalw [constrains_def] "(F : A co {}) = (A={})";
paulson@7826
   137
by (Blast_tac 1);
paulson@7826
   138
qed "constrains_empty2";
paulson@7826
   139
paulson@7826
   140
Goalw [constrains_def] "(F : UNIV co B) = (B = UNIV)";
paulson@7826
   141
by (Blast_tac 1);
paulson@7826
   142
qed "constrains_UNIV";
paulson@7826
   143
paulson@6536
   144
Goalw [constrains_def] "F : A co UNIV";
paulson@4776
   145
by (Blast_tac 1);
paulson@7826
   146
qed "constrains_UNIV2";
paulson@7826
   147
paulson@7826
   148
AddIffs [constrains_empty, constrains_empty2, 
paulson@7826
   149
	 constrains_UNIV, constrains_UNIV2];
paulson@4776
   150
paulson@5648
   151
(*monotonic in 2nd argument*)
wenzelm@5069
   152
Goalw [constrains_def]
paulson@6536
   153
    "[| F : A co A'; A'<=B' |] ==> F : A co B'";
paulson@4776
   154
by (Blast_tac 1);
paulson@4776
   155
qed "constrains_weaken_R";
paulson@4776
   156
paulson@5648
   157
(*anti-monotonic in 1st argument*)
wenzelm@5069
   158
Goalw [constrains_def]
paulson@6536
   159
    "[| F : A co A'; B<=A |] ==> F : B co A'";
paulson@4776
   160
by (Blast_tac 1);
paulson@4776
   161
qed "constrains_weaken_L";
paulson@4776
   162
wenzelm@5069
   163
Goalw [constrains_def]
paulson@6536
   164
   "[| F : A co A'; B<=A; A'<=B' |] ==> F : B co B'";
paulson@4776
   165
by (Blast_tac 1);
paulson@4776
   166
qed "constrains_weaken";
paulson@4776
   167
paulson@4776
   168
(** Union **)
paulson@4776
   169
wenzelm@5069
   170
Goalw [constrains_def]
paulson@7345
   171
    "[| F : A co A'; F : B co B' |] ==> F : (A Un B) co (A' Un B')";
paulson@4776
   172
by (Blast_tac 1);
paulson@4776
   173
qed "constrains_Un";
paulson@4776
   174
wenzelm@5069
   175
Goalw [constrains_def]
paulson@7345
   176
    "ALL i:I. F : (A i) co (A' i) ==> F : (UN i:I. A i) co (UN i:I. A' i)";
paulson@4776
   177
by (Blast_tac 1);
paulson@4776
   178
qed "ball_constrains_UN";
paulson@4776
   179
paulson@7826
   180
Goalw [constrains_def] "(A Un B) co C = (A co C) Int (B co C)";
paulson@7826
   181
by (Blast_tac 1);
paulson@7826
   182
qed "constrains_Un_distrib";
paulson@7826
   183
paulson@7826
   184
Goalw [constrains_def] "(UN i:I. A i) co B = (INT i:I. A i co B)";
paulson@7826
   185
by (Blast_tac 1);
paulson@7826
   186
qed "constrains_UN_distrib";
paulson@7826
   187
paulson@7826
   188
Goalw [constrains_def] "C co (A Int B) = (C co A) Int (C co B)";
paulson@7826
   189
by (Blast_tac 1);
paulson@7826
   190
qed "constrains_Int_distrib";
paulson@7826
   191
paulson@7826
   192
Goalw [constrains_def] "A co (INT i:I. B i) = (INT i:I. A co B i)";
paulson@7826
   193
by (Blast_tac 1);
paulson@7826
   194
qed "constrains_INT_distrib";
paulson@7826
   195
paulson@4776
   196
(** Intersection **)
paulson@4776
   197
wenzelm@5069
   198
Goalw [constrains_def]
paulson@7345
   199
    "[| F : A co A'; F : B co B' |] ==> F : (A Int B) co (A' Int B')";
paulson@4776
   200
by (Blast_tac 1);
paulson@4776
   201
qed "constrains_Int";
paulson@4776
   202
wenzelm@5069
   203
Goalw [constrains_def]
paulson@7345
   204
    "ALL i:I. F : (A i) co (A' i) ==> F : (INT i:I. A i) co (INT i:I. A' i)";
paulson@4776
   205
by (Blast_tac 1);
paulson@4776
   206
qed "ball_constrains_INT";
paulson@4776
   207
paulson@6536
   208
Goalw [constrains_def] "F : A co A' ==> A <= A'";
paulson@6295
   209
by Auto_tac;
paulson@5277
   210
qed "constrains_imp_subset";
paulson@4776
   211
paulson@6536
   212
(*The reasoning is by subsets since "co" refers to single actions
paulson@6012
   213
  only.  So this rule isn't that useful.*)
paulson@6295
   214
Goalw [constrains_def]
paulson@6536
   215
    "[| F : A co B; F : B co C |] ==> F : A co C";
paulson@6295
   216
by (Blast_tac 1);
paulson@5277
   217
qed "constrains_trans";
paulson@4776
   218
paulson@6295
   219
Goalw [constrains_def]
paulson@7345
   220
   "[| F : A co (A' Un B); F : B co B' |] ==> F : A co (A' Un B')";
paulson@6295
   221
by (Clarify_tac 1);
paulson@6295
   222
by (Blast_tac 1);
paulson@6012
   223
qed "constrains_cancel";
paulson@6012
   224
paulson@4776
   225
paulson@7630
   226
(*** unless ***)
paulson@7630
   227
paulson@7630
   228
Goalw [unless_def] "F : (A-B) co (A Un B) ==> F : A unless B";
paulson@7630
   229
by (assume_tac 1);
paulson@7630
   230
qed "unlessI";
paulson@7630
   231
paulson@7630
   232
Goalw [unless_def] "F : A unless B ==> F : (A-B) co (A Un B)";
paulson@7630
   233
by (assume_tac 1);
paulson@7630
   234
qed "unlessD";
paulson@7630
   235
paulson@7630
   236
paulson@4776
   237
(*** stable ***)
paulson@4776
   238
paulson@6536
   239
Goalw [stable_def] "F : A co A ==> F : stable A";
paulson@4776
   240
by (assume_tac 1);
paulson@4776
   241
qed "stableI";
paulson@4776
   242
paulson@6536
   243
Goalw [stable_def] "F : stable A ==> F : A co A";
paulson@4776
   244
by (assume_tac 1);
paulson@4776
   245
qed "stableD";
paulson@4776
   246
paulson@7594
   247
Goalw [stable_def, constrains_def] "stable UNIV = UNIV";
paulson@7594
   248
by Auto_tac;
paulson@7594
   249
qed "stable_UNIV";
paulson@7594
   250
Addsimps [stable_UNIV];
paulson@7594
   251
paulson@5804
   252
(** Union **)
paulson@5804
   253
wenzelm@5069
   254
Goalw [stable_def]
paulson@5648
   255
    "[| F : stable A; F : stable A' |] ==> F : stable (A Un A')";
paulson@4776
   256
by (blast_tac (claset() addIs [constrains_Un]) 1);
paulson@4776
   257
qed "stable_Un";
paulson@4776
   258
wenzelm@5069
   259
Goalw [stable_def]
paulson@5804
   260
    "ALL i:I. F : stable (A i) ==> F : stable (UN i:I. A i)";
paulson@5804
   261
by (blast_tac (claset() addIs [ball_constrains_UN]) 1);
paulson@5804
   262
qed "ball_stable_UN";
paulson@5804
   263
paulson@5804
   264
(** Intersection **)
paulson@5804
   265
paulson@5804
   266
Goalw [stable_def]
paulson@5648
   267
    "[| F : stable A; F : stable A' |] ==> F : stable (A Int A')";
paulson@4776
   268
by (blast_tac (claset() addIs [constrains_Int]) 1);
paulson@4776
   269
qed "stable_Int";
paulson@4776
   270
paulson@5804
   271
Goalw [stable_def]
paulson@5804
   272
    "ALL i:I. F : stable (A i) ==> F : stable (INT i:I. A i)";
paulson@5804
   273
by (blast_tac (claset() addIs [ball_constrains_INT]) 1);
paulson@5804
   274
qed "ball_stable_INT";
paulson@5804
   275
paulson@5277
   276
Goalw [stable_def, constrains_def]
paulson@7345
   277
    "[| F : stable C; F : A co (C Un A') |] ==> F : (C Un A) co (C Un A')";
paulson@4776
   278
by (Blast_tac 1);
paulson@5277
   279
qed "stable_constrains_Un";
paulson@4776
   280
paulson@5277
   281
Goalw [stable_def, constrains_def]
paulson@7345
   282
  "[| F : stable C; F :  (C Int A) co  A' |] ==> F : (C Int A) co (C Int A')";
paulson@4776
   283
by (Blast_tac 1);
paulson@5277
   284
qed "stable_constrains_Int";
paulson@4776
   285
paulson@6536
   286
(*[| F : stable C; F :  co (C Int A) A |] ==> F : stable (C Int A)*)
paulson@5648
   287
bind_thm ("stable_constrains_stable", stable_constrains_Int RS stableI);
paulson@5648
   288
paulson@5648
   289
paulson@5804
   290
(*** invariant ***)
paulson@5648
   291
paulson@5648
   292
Goal "[| Init F<=A;  F: stable A |] ==> F : invariant A";
paulson@5648
   293
by (asm_simp_tac (simpset() addsimps [invariant_def]) 1);
paulson@5648
   294
qed "invariantI";
paulson@5648
   295
paulson@5648
   296
(*Could also say "invariant A Int invariant B <= invariant (A Int B)"*)
paulson@5648
   297
Goal "[| F : invariant A;  F : invariant B |] ==> F : invariant (A Int B)";
paulson@5648
   298
by (auto_tac (claset(), simpset() addsimps [invariant_def, stable_Int]));
paulson@5648
   299
qed "invariant_Int";
paulson@5648
   300
paulson@5648
   301
paulson@5648
   302
(*** increasing ***)
paulson@5648
   303
paulson@5648
   304
Goalw [increasing_def, stable_def, constrains_def]
paulson@6712
   305
     "mono g ==> increasing f <= increasing (g o f)";
paulson@5648
   306
by Auto_tac;
paulson@6712
   307
by (blast_tac (claset() addIs [monoD, order_trans]) 1);
paulson@6712
   308
qed "mono_increasing_o";
paulson@5648
   309
paulson@5648
   310
Goalw [increasing_def]
paulson@5648
   311
     "increasing f <= {F. ALL z::nat. F: stable {s. z < f s}}";
paulson@5648
   312
by (simp_tac (simpset() addsimps [Suc_le_eq RS sym]) 1);
paulson@5648
   313
by (Blast_tac 1);
paulson@5804
   314
qed "increasing_stable_less";
paulson@5648
   315
paulson@5648
   316
paulson@5648
   317
(** The Elimination Theorem.  The "free" m has become universally quantified!
paulson@5648
   318
    Should the premise be !!m instead of ALL m ?  Would make it harder to use
paulson@5648
   319
    in forward proof. **)
paulson@5648
   320
wenzelm@5069
   321
Goalw [constrains_def]
paulson@6536
   322
    "[| ALL m:M. F : {s. s x = m} co (B m) |] \
paulson@6536
   323
\    ==> F : {s. s x : M} co (UN m:M. B m)";
paulson@4776
   324
by (Blast_tac 1);
paulson@4776
   325
qed "elimination";
paulson@4776
   326
paulson@4776
   327
(*As above, but for the trivial case of a one-variable state, in which the
paulson@4776
   328
  state is identified with its one variable.*)
wenzelm@5069
   329
Goalw [constrains_def]
paulson@6536
   330
    "(ALL m:M. F : {m} co (B m)) ==> F : M co (UN m:M. B m)";
paulson@4776
   331
by (Blast_tac 1);
paulson@4776
   332
qed "elimination_sing";
paulson@4776
   333
paulson@4776
   334
paulson@4776
   335
paulson@4776
   336
(*** Theoretical Results from Section 6 ***)
paulson@4776
   337
wenzelm@5069
   338
Goalw [constrains_def, strongest_rhs_def]
paulson@6536
   339
    "F : A co (strongest_rhs F A )";
paulson@4776
   340
by (Blast_tac 1);
paulson@4776
   341
qed "constrains_strongest_rhs";
paulson@4776
   342
wenzelm@5069
   343
Goalw [constrains_def, strongest_rhs_def]
paulson@6536
   344
    "F : A co B ==> strongest_rhs F A <= B";
paulson@4776
   345
by (Blast_tac 1);
paulson@4776
   346
qed "strongest_rhs_is_strongest";