src/HOL/Univ.ML
author clasohm
Fri Mar 03 12:02:25 1995 +0100 (1995-03-03)
changeset 923 ff1574a81019
child 972 e61b058d58d2
permissions -rw-r--r--
new version of HOL with curried function application
clasohm@923
     1
(*  Title: 	HOL/univ
clasohm@923
     2
    ID:         $Id$
clasohm@923
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1991  University of Cambridge
clasohm@923
     5
clasohm@923
     6
For univ.thy
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
open Univ;
clasohm@923
    10
clasohm@923
    11
(** LEAST -- the least number operator **)
clasohm@923
    12
clasohm@923
    13
clasohm@923
    14
val [prem1,prem2] = goalw Univ.thy [Least_def]
clasohm@923
    15
    "[| P(k);  !!x. x<k ==> ~P(x) |] ==> (LEAST x.P(x)) = k";
clasohm@923
    16
by (rtac select_equality 1);
clasohm@923
    17
by (fast_tac (HOL_cs addSIs [prem1,prem2]) 1);
clasohm@923
    18
by (cut_facts_tac [less_linear] 1);
clasohm@923
    19
by (fast_tac (HOL_cs addSIs [prem1] addSDs [prem2]) 1);
clasohm@923
    20
qed "Least_equality";
clasohm@923
    21
clasohm@923
    22
val [prem] = goal Univ.thy "P(k) ==> P(LEAST x.P(x))";
clasohm@923
    23
by (rtac (prem RS rev_mp) 1);
clasohm@923
    24
by (res_inst_tac [("n","k")] less_induct 1);
clasohm@923
    25
by (rtac impI 1);
clasohm@923
    26
by (rtac classical 1);
clasohm@923
    27
by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1);
clasohm@923
    28
by (assume_tac 1);
clasohm@923
    29
by (assume_tac 2);
clasohm@923
    30
by (fast_tac HOL_cs 1);
clasohm@923
    31
qed "LeastI";
clasohm@923
    32
clasohm@923
    33
(*Proof is almost identical to the one above!*)
clasohm@923
    34
val [prem] = goal Univ.thy "P(k) ==> (LEAST x.P(x)) <= k";
clasohm@923
    35
by (rtac (prem RS rev_mp) 1);
clasohm@923
    36
by (res_inst_tac [("n","k")] less_induct 1);
clasohm@923
    37
by (rtac impI 1);
clasohm@923
    38
by (rtac classical 1);
clasohm@923
    39
by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1);
clasohm@923
    40
by (assume_tac 1);
clasohm@923
    41
by (rtac le_refl 2);
clasohm@923
    42
by (fast_tac (HOL_cs addIs [less_imp_le,le_trans]) 1);
clasohm@923
    43
qed "Least_le";
clasohm@923
    44
clasohm@923
    45
val [prem] = goal Univ.thy "k < (LEAST x.P(x)) ==> ~P(k)";
clasohm@923
    46
by (rtac notI 1);
clasohm@923
    47
by (etac (rewrite_rule [le_def] Least_le RS notE) 1);
clasohm@923
    48
by (rtac prem 1);
clasohm@923
    49
qed "not_less_Least";
clasohm@923
    50
clasohm@923
    51
clasohm@923
    52
(** apfst -- can be used in similar type definitions **)
clasohm@923
    53
clasohm@923
    54
goalw Univ.thy [apfst_def] "apfst f <a,b> = <f(a),b>";
clasohm@923
    55
by (rtac split 1);
clasohm@923
    56
qed "apfst";
clasohm@923
    57
clasohm@923
    58
val [major,minor] = goal Univ.thy
clasohm@923
    59
    "[| q = apfst f p;  !!x y. [| p = <x,y>;  q = <f(x),y> |] ==> R \
clasohm@923
    60
\    |] ==> R";
clasohm@923
    61
by (rtac PairE 1);
clasohm@923
    62
by (rtac minor 1);
clasohm@923
    63
by (assume_tac 1);
clasohm@923
    64
by (rtac (major RS trans) 1);
clasohm@923
    65
by (etac ssubst 1);
clasohm@923
    66
by (rtac apfst 1);
clasohm@923
    67
qed "apfstE";
clasohm@923
    68
clasohm@923
    69
(** Push -- an injection, analogous to Cons on lists **)
clasohm@923
    70
clasohm@923
    71
val [major] = goalw Univ.thy [Push_def] "Push i f =Push j g  ==> i=j";
clasohm@923
    72
by (rtac (major RS fun_cong RS box_equals RS Suc_inject) 1);
clasohm@923
    73
by (rtac nat_case_0 1);
clasohm@923
    74
by (rtac nat_case_0 1);
clasohm@923
    75
qed "Push_inject1";
clasohm@923
    76
clasohm@923
    77
val [major] = goalw Univ.thy [Push_def] "Push i f =Push j g  ==> f=g";
clasohm@923
    78
by (rtac (major RS fun_cong RS ext RS box_equals) 1);
clasohm@923
    79
by (rtac (nat_case_Suc RS ext) 1);
clasohm@923
    80
by (rtac (nat_case_Suc RS ext) 1);
clasohm@923
    81
qed "Push_inject2";
clasohm@923
    82
clasohm@923
    83
val [major,minor] = goal Univ.thy
clasohm@923
    84
    "[| Push i f =Push j g;  [| i=j;  f=g |] ==> P \
clasohm@923
    85
\    |] ==> P";
clasohm@923
    86
by (rtac ((major RS Push_inject2) RS ((major RS Push_inject1) RS minor)) 1);
clasohm@923
    87
qed "Push_inject";
clasohm@923
    88
clasohm@923
    89
val [major] = goalw Univ.thy [Push_def] "Push k f =(%z.0) ==> P";
clasohm@923
    90
by (rtac (major RS fun_cong RS box_equals RS Suc_neq_Zero) 1);
clasohm@923
    91
by (rtac nat_case_0 1);
clasohm@923
    92
by (rtac refl 1);
clasohm@923
    93
qed "Push_neq_K0";
clasohm@923
    94
clasohm@923
    95
(*** Isomorphisms ***)
clasohm@923
    96
clasohm@923
    97
goal Univ.thy "inj(Rep_Node)";
clasohm@923
    98
by (rtac inj_inverseI 1);	(*cannot combine by RS: multiple unifiers*)
clasohm@923
    99
by (rtac Rep_Node_inverse 1);
clasohm@923
   100
qed "inj_Rep_Node";
clasohm@923
   101
clasohm@923
   102
goal Univ.thy "inj_onto Abs_Node Node";
clasohm@923
   103
by (rtac inj_onto_inverseI 1);
clasohm@923
   104
by (etac Abs_Node_inverse 1);
clasohm@923
   105
qed "inj_onto_Abs_Node";
clasohm@923
   106
clasohm@923
   107
val Abs_Node_inject = inj_onto_Abs_Node RS inj_ontoD;
clasohm@923
   108
clasohm@923
   109
clasohm@923
   110
(*** Introduction rules for Node ***)
clasohm@923
   111
clasohm@923
   112
goalw Univ.thy [Node_def] "<%k. 0,a> : Node";
clasohm@923
   113
by (fast_tac set_cs 1);
clasohm@923
   114
qed "Node_K0_I";
clasohm@923
   115
clasohm@923
   116
goalw Univ.thy [Node_def,Push_def]
clasohm@923
   117
    "!!p. p: Node ==> apfst (Push i) p : Node";
clasohm@923
   118
by (fast_tac (set_cs addSIs [apfst, nat_case_Suc RS trans]) 1);
clasohm@923
   119
qed "Node_Push_I";
clasohm@923
   120
clasohm@923
   121
clasohm@923
   122
(*** Distinctness of constructors ***)
clasohm@923
   123
clasohm@923
   124
(** Scons vs Atom **)
clasohm@923
   125
clasohm@923
   126
goalw Univ.thy [Atom_def,Scons_def,Push_Node_def] "(M$N) ~= Atom(a)";
clasohm@923
   127
by (rtac notI 1);
clasohm@923
   128
by (etac (equalityD2 RS subsetD RS UnE) 1);
clasohm@923
   129
by (rtac singletonI 1);
clasohm@923
   130
by (REPEAT (eresolve_tac [imageE, Abs_Node_inject RS apfstE, 
clasohm@923
   131
			  Pair_inject, sym RS Push_neq_K0] 1
clasohm@923
   132
     ORELSE resolve_tac [Node_K0_I, Rep_Node RS Node_Push_I] 1));
clasohm@923
   133
qed "Scons_not_Atom";
clasohm@923
   134
bind_thm ("Atom_not_Scons", (Scons_not_Atom RS not_sym));
clasohm@923
   135
clasohm@923
   136
bind_thm ("Scons_neq_Atom", (Scons_not_Atom RS notE));
clasohm@923
   137
val Atom_neq_Scons = sym RS Scons_neq_Atom;
clasohm@923
   138
clasohm@923
   139
(*** Injectiveness ***)
clasohm@923
   140
clasohm@923
   141
(** Atomic nodes **)
clasohm@923
   142
clasohm@923
   143
goalw Univ.thy [Atom_def] "inj(Atom)";
clasohm@923
   144
by (rtac injI 1);
clasohm@923
   145
by (etac (singleton_inject RS Abs_Node_inject RS Pair_inject) 1);
clasohm@923
   146
by (REPEAT (ares_tac [Node_K0_I] 1));
clasohm@923
   147
qed "inj_Atom";
clasohm@923
   148
val Atom_inject = inj_Atom RS injD;
clasohm@923
   149
clasohm@923
   150
goalw Univ.thy [Leaf_def,o_def] "inj(Leaf)";
clasohm@923
   151
by (rtac injI 1);
clasohm@923
   152
by (etac (Atom_inject RS Inl_inject) 1);
clasohm@923
   153
qed "inj_Leaf";
clasohm@923
   154
clasohm@923
   155
val Leaf_inject = inj_Leaf RS injD;
clasohm@923
   156
clasohm@923
   157
goalw Univ.thy [Numb_def,o_def] "inj(Numb)";
clasohm@923
   158
by (rtac injI 1);
clasohm@923
   159
by (etac (Atom_inject RS Inr_inject) 1);
clasohm@923
   160
qed "inj_Numb";
clasohm@923
   161
clasohm@923
   162
val Numb_inject = inj_Numb RS injD;
clasohm@923
   163
clasohm@923
   164
(** Injectiveness of Push_Node **)
clasohm@923
   165
clasohm@923
   166
val [major,minor] = goalw Univ.thy [Push_Node_def]
clasohm@923
   167
    "[| Push_Node i m =Push_Node j n;  [| i=j;  m=n |] ==> P \
clasohm@923
   168
\    |] ==> P";
clasohm@923
   169
by (rtac (major RS Abs_Node_inject RS apfstE) 1);
clasohm@923
   170
by (REPEAT (resolve_tac [Rep_Node RS Node_Push_I] 1));
clasohm@923
   171
by (etac (sym RS apfstE) 1);
clasohm@923
   172
by (rtac minor 1);
clasohm@923
   173
by (etac Pair_inject 1);
clasohm@923
   174
by (etac (Push_inject1 RS sym) 1);
clasohm@923
   175
by (rtac (inj_Rep_Node RS injD) 1);
clasohm@923
   176
by (etac trans 1);
clasohm@923
   177
by (safe_tac (HOL_cs addSEs [Pair_inject,Push_inject,sym]));
clasohm@923
   178
qed "Push_Node_inject";
clasohm@923
   179
clasohm@923
   180
clasohm@923
   181
(** Injectiveness of Scons **)
clasohm@923
   182
clasohm@923
   183
val [major] = goalw Univ.thy [Scons_def] "M$N <= M'$N' ==> M<=M'";
clasohm@923
   184
by (cut_facts_tac [major] 1);
clasohm@923
   185
by (fast_tac (set_cs addSDs [Suc_inject]
clasohm@923
   186
		     addSEs [Push_Node_inject, Zero_neq_Suc]) 1);
clasohm@923
   187
qed "Scons_inject_lemma1";
clasohm@923
   188
clasohm@923
   189
val [major] = goalw Univ.thy [Scons_def] "M$N <= M'$N' ==> N<=N'";
clasohm@923
   190
by (cut_facts_tac [major] 1);
clasohm@923
   191
by (fast_tac (set_cs addSDs [Suc_inject]
clasohm@923
   192
		     addSEs [Push_Node_inject, Suc_neq_Zero]) 1);
clasohm@923
   193
qed "Scons_inject_lemma2";
clasohm@923
   194
clasohm@923
   195
val [major] = goal Univ.thy "M$N = M'$N' ==> M=M'";
clasohm@923
   196
by (rtac (major RS equalityE) 1);
clasohm@923
   197
by (REPEAT (ares_tac [equalityI, Scons_inject_lemma1] 1));
clasohm@923
   198
qed "Scons_inject1";
clasohm@923
   199
clasohm@923
   200
val [major] = goal Univ.thy "M$N = M'$N' ==> N=N'";
clasohm@923
   201
by (rtac (major RS equalityE) 1);
clasohm@923
   202
by (REPEAT (ares_tac [equalityI, Scons_inject_lemma2] 1));
clasohm@923
   203
qed "Scons_inject2";
clasohm@923
   204
clasohm@923
   205
val [major,minor] = goal Univ.thy
clasohm@923
   206
    "[| M$N = M'$N';  [| M=M';  N=N' |] ==> P \
clasohm@923
   207
\    |] ==> P";
clasohm@923
   208
by (rtac ((major RS Scons_inject2) RS ((major RS Scons_inject1) RS minor)) 1);
clasohm@923
   209
qed "Scons_inject";
clasohm@923
   210
clasohm@923
   211
(*rewrite rules*)
clasohm@923
   212
goal Univ.thy "(Atom(a)=Atom(b)) = (a=b)";
clasohm@923
   213
by (fast_tac (HOL_cs addSEs [Atom_inject]) 1);
clasohm@923
   214
qed "Atom_Atom_eq";
clasohm@923
   215
clasohm@923
   216
goal Univ.thy "(M$N = M'$N') = (M=M' & N=N')";
clasohm@923
   217
by (fast_tac (HOL_cs addSEs [Scons_inject]) 1);
clasohm@923
   218
qed "Scons_Scons_eq";
clasohm@923
   219
clasohm@923
   220
(*** Distinctness involving Leaf and Numb ***)
clasohm@923
   221
clasohm@923
   222
(** Scons vs Leaf **)
clasohm@923
   223
clasohm@923
   224
goalw Univ.thy [Leaf_def,o_def] "(M$N) ~= Leaf(a)";
clasohm@923
   225
by (rtac Scons_not_Atom 1);
clasohm@923
   226
qed "Scons_not_Leaf";
clasohm@923
   227
bind_thm ("Leaf_not_Scons", (Scons_not_Leaf RS not_sym));
clasohm@923
   228
clasohm@923
   229
bind_thm ("Scons_neq_Leaf", (Scons_not_Leaf RS notE));
clasohm@923
   230
val Leaf_neq_Scons = sym RS Scons_neq_Leaf;
clasohm@923
   231
clasohm@923
   232
(** Scons vs Numb **)
clasohm@923
   233
clasohm@923
   234
goalw Univ.thy [Numb_def,o_def] "(M$N) ~= Numb(k)";
clasohm@923
   235
by (rtac Scons_not_Atom 1);
clasohm@923
   236
qed "Scons_not_Numb";
clasohm@923
   237
bind_thm ("Numb_not_Scons", (Scons_not_Numb RS not_sym));
clasohm@923
   238
clasohm@923
   239
bind_thm ("Scons_neq_Numb", (Scons_not_Numb RS notE));
clasohm@923
   240
val Numb_neq_Scons = sym RS Scons_neq_Numb;
clasohm@923
   241
clasohm@923
   242
(** Leaf vs Numb **)
clasohm@923
   243
clasohm@923
   244
goalw Univ.thy [Leaf_def,Numb_def] "Leaf(a) ~= Numb(k)";
clasohm@923
   245
by (simp_tac (HOL_ss addsimps [Atom_Atom_eq,Inl_not_Inr]) 1);
clasohm@923
   246
qed "Leaf_not_Numb";
clasohm@923
   247
bind_thm ("Numb_not_Leaf", (Leaf_not_Numb RS not_sym));
clasohm@923
   248
clasohm@923
   249
bind_thm ("Leaf_neq_Numb", (Leaf_not_Numb RS notE));
clasohm@923
   250
val Numb_neq_Leaf = sym RS Leaf_neq_Numb;
clasohm@923
   251
clasohm@923
   252
clasohm@923
   253
(*** ndepth -- the depth of a node ***)
clasohm@923
   254
clasohm@923
   255
val univ_simps = [apfst,Scons_not_Atom,Atom_not_Scons,Scons_Scons_eq];
clasohm@923
   256
val univ_ss = nat_ss addsimps univ_simps;
clasohm@923
   257
clasohm@923
   258
clasohm@923
   259
goalw Univ.thy [ndepth_def] "ndepth (Abs_Node(<%k.0, x>)) = 0";
clasohm@923
   260
by (sstac [Node_K0_I RS Abs_Node_inverse, split] 1);
clasohm@923
   261
by (rtac Least_equality 1);
clasohm@923
   262
by (rtac refl 1);
clasohm@923
   263
by (etac less_zeroE 1);
clasohm@923
   264
qed "ndepth_K0";
clasohm@923
   265
clasohm@923
   266
goal Univ.thy "k < Suc(LEAST x. f(x)=0) --> nat_case (Suc i) f k ~= 0";
clasohm@923
   267
by (nat_ind_tac "k" 1);
clasohm@923
   268
by (ALLGOALS (simp_tac nat_ss));
clasohm@923
   269
by (rtac impI 1);
clasohm@923
   270
by (etac not_less_Least 1);
clasohm@923
   271
qed "ndepth_Push_lemma";
clasohm@923
   272
clasohm@923
   273
goalw Univ.thy [ndepth_def,Push_Node_def]
clasohm@923
   274
    "ndepth (Push_Node i n) = Suc(ndepth(n))";
clasohm@923
   275
by (stac (Rep_Node RS Node_Push_I RS Abs_Node_inverse) 1);
clasohm@923
   276
by (cut_facts_tac [rewrite_rule [Node_def] Rep_Node] 1);
clasohm@923
   277
by (safe_tac set_cs);
clasohm@923
   278
be ssubst 1;  (*instantiates type variables!*)
clasohm@923
   279
by (simp_tac univ_ss 1);
clasohm@923
   280
by (rtac Least_equality 1);
clasohm@923
   281
by (rewtac Push_def);
clasohm@923
   282
by (rtac (nat_case_Suc RS trans) 1);
clasohm@923
   283
by (etac LeastI 1);
clasohm@923
   284
by (etac (ndepth_Push_lemma RS mp) 1);
clasohm@923
   285
qed "ndepth_Push_Node";
clasohm@923
   286
clasohm@923
   287
clasohm@923
   288
(*** ntrunc applied to the various node sets ***)
clasohm@923
   289
clasohm@923
   290
goalw Univ.thy [ntrunc_def] "ntrunc 0 M = {}";
clasohm@923
   291
by (safe_tac (set_cs addSIs [equalityI] addSEs [less_zeroE]));
clasohm@923
   292
qed "ntrunc_0";
clasohm@923
   293
clasohm@923
   294
goalw Univ.thy [Atom_def,ntrunc_def] "ntrunc (Suc k) (Atom a) = Atom(a)";
clasohm@923
   295
by (safe_tac (set_cs addSIs [equalityI]));
clasohm@923
   296
by (stac ndepth_K0 1);
clasohm@923
   297
by (rtac zero_less_Suc 1);
clasohm@923
   298
qed "ntrunc_Atom";
clasohm@923
   299
clasohm@923
   300
goalw Univ.thy [Leaf_def,o_def] "ntrunc (Suc k) (Leaf a) = Leaf(a)";
clasohm@923
   301
by (rtac ntrunc_Atom 1);
clasohm@923
   302
qed "ntrunc_Leaf";
clasohm@923
   303
clasohm@923
   304
goalw Univ.thy [Numb_def,o_def] "ntrunc (Suc k) (Numb i) = Numb(i)";
clasohm@923
   305
by (rtac ntrunc_Atom 1);
clasohm@923
   306
qed "ntrunc_Numb";
clasohm@923
   307
clasohm@923
   308
goalw Univ.thy [Scons_def,ntrunc_def]
clasohm@923
   309
    "ntrunc (Suc k) (M$N) = ntrunc k M $ ntrunc k N";
clasohm@923
   310
by (safe_tac (set_cs addSIs [equalityI,imageI]));
clasohm@923
   311
by (REPEAT (stac ndepth_Push_Node 3 THEN etac Suc_mono 3));
clasohm@923
   312
by (REPEAT (rtac Suc_less_SucD 1 THEN 
clasohm@923
   313
	    rtac (ndepth_Push_Node RS subst) 1 THEN 
clasohm@923
   314
	    assume_tac 1));
clasohm@923
   315
qed "ntrunc_Scons";
clasohm@923
   316
clasohm@923
   317
(** Injection nodes **)
clasohm@923
   318
clasohm@923
   319
goalw Univ.thy [In0_def] "ntrunc (Suc 0) (In0 M) = {}";
clasohm@923
   320
by (simp_tac (univ_ss addsimps [ntrunc_Scons,ntrunc_0]) 1);
clasohm@923
   321
by (rewtac Scons_def);
clasohm@923
   322
by (safe_tac (set_cs addSIs [equalityI]));
clasohm@923
   323
qed "ntrunc_one_In0";
clasohm@923
   324
clasohm@923
   325
goalw Univ.thy [In0_def]
clasohm@923
   326
    "ntrunc (Suc (Suc k)) (In0 M) = In0 (ntrunc (Suc k) M)";
clasohm@923
   327
by (simp_tac (univ_ss addsimps [ntrunc_Scons,ntrunc_Numb]) 1);
clasohm@923
   328
qed "ntrunc_In0";
clasohm@923
   329
clasohm@923
   330
goalw Univ.thy [In1_def] "ntrunc (Suc 0) (In1 M) = {}";
clasohm@923
   331
by (simp_tac (univ_ss addsimps [ntrunc_Scons,ntrunc_0]) 1);
clasohm@923
   332
by (rewtac Scons_def);
clasohm@923
   333
by (safe_tac (set_cs addSIs [equalityI]));
clasohm@923
   334
qed "ntrunc_one_In1";
clasohm@923
   335
clasohm@923
   336
goalw Univ.thy [In1_def]
clasohm@923
   337
    "ntrunc (Suc (Suc k)) (In1 M) = In1 (ntrunc (Suc k) M)";
clasohm@923
   338
by (simp_tac (univ_ss addsimps [ntrunc_Scons,ntrunc_Numb]) 1);
clasohm@923
   339
qed "ntrunc_In1";
clasohm@923
   340
clasohm@923
   341
clasohm@923
   342
(*** Cartesian Product ***)
clasohm@923
   343
clasohm@923
   344
goalw Univ.thy [uprod_def] "!!M N. [| M:A;  N:B |] ==> (M$N) : A<*>B";
clasohm@923
   345
by (REPEAT (ares_tac [singletonI,UN_I] 1));
clasohm@923
   346
qed "uprodI";
clasohm@923
   347
clasohm@923
   348
(*The general elimination rule*)
clasohm@923
   349
val major::prems = goalw Univ.thy [uprod_def]
clasohm@923
   350
    "[| c : A<*>B;  \
clasohm@923
   351
\       !!x y. [| x:A;  y:B;  c=x$y |] ==> P \
clasohm@923
   352
\    |] ==> P";
clasohm@923
   353
by (cut_facts_tac [major] 1);
clasohm@923
   354
by (REPEAT (eresolve_tac [asm_rl,singletonE,UN_E] 1
clasohm@923
   355
     ORELSE resolve_tac prems 1));
clasohm@923
   356
qed "uprodE";
clasohm@923
   357
clasohm@923
   358
(*Elimination of a pair -- introduces no eigenvariables*)
clasohm@923
   359
val prems = goal Univ.thy
clasohm@923
   360
    "[| (M$N) : A<*>B;      [| M:A;  N:B |] ==> P   \
clasohm@923
   361
\    |] ==> P";
clasohm@923
   362
by (rtac uprodE 1);
clasohm@923
   363
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Scons_inject,ssubst] 1));
clasohm@923
   364
qed "uprodE2";
clasohm@923
   365
clasohm@923
   366
clasohm@923
   367
(*** Disjoint Sum ***)
clasohm@923
   368
clasohm@923
   369
goalw Univ.thy [usum_def] "!!M. M:A ==> In0(M) : A<+>B";
clasohm@923
   370
by (fast_tac set_cs 1);
clasohm@923
   371
qed "usum_In0I";
clasohm@923
   372
clasohm@923
   373
goalw Univ.thy [usum_def] "!!N. N:B ==> In1(N) : A<+>B";
clasohm@923
   374
by (fast_tac set_cs 1);
clasohm@923
   375
qed "usum_In1I";
clasohm@923
   376
clasohm@923
   377
val major::prems = goalw Univ.thy [usum_def]
clasohm@923
   378
    "[| u : A<+>B;  \
clasohm@923
   379
\       !!x. [| x:A;  u=In0(x) |] ==> P; \
clasohm@923
   380
\       !!y. [| y:B;  u=In1(y) |] ==> P \
clasohm@923
   381
\    |] ==> P";
clasohm@923
   382
by (rtac (major RS UnE) 1);
clasohm@923
   383
by (REPEAT (rtac refl 1 
clasohm@923
   384
     ORELSE eresolve_tac (prems@[imageE,ssubst]) 1));
clasohm@923
   385
qed "usumE";
clasohm@923
   386
clasohm@923
   387
clasohm@923
   388
(** Injection **)
clasohm@923
   389
clasohm@923
   390
goalw Univ.thy [In0_def,In1_def] "In0(M) ~= In1(N)";
clasohm@923
   391
by (rtac notI 1);
clasohm@923
   392
by (etac (Scons_inject1 RS Numb_inject RS Zero_neq_Suc) 1);
clasohm@923
   393
qed "In0_not_In1";
clasohm@923
   394
clasohm@923
   395
bind_thm ("In1_not_In0", (In0_not_In1 RS not_sym));
clasohm@923
   396
bind_thm ("In0_neq_In1", (In0_not_In1 RS notE));
clasohm@923
   397
val In1_neq_In0 = sym RS In0_neq_In1;
clasohm@923
   398
clasohm@923
   399
val [major] = goalw Univ.thy [In0_def] "In0(M) = In0(N) ==>  M=N";
clasohm@923
   400
by (rtac (major RS Scons_inject2) 1);
clasohm@923
   401
qed "In0_inject";
clasohm@923
   402
clasohm@923
   403
val [major] = goalw Univ.thy [In1_def] "In1(M) = In1(N) ==>  M=N";
clasohm@923
   404
by (rtac (major RS Scons_inject2) 1);
clasohm@923
   405
qed "In1_inject";
clasohm@923
   406
clasohm@923
   407
clasohm@923
   408
(*** proving equality of sets and functions using ntrunc ***)
clasohm@923
   409
clasohm@923
   410
goalw Univ.thy [ntrunc_def] "ntrunc k M <= M";
clasohm@923
   411
by (fast_tac set_cs 1);
clasohm@923
   412
qed "ntrunc_subsetI";
clasohm@923
   413
clasohm@923
   414
val [major] = goalw Univ.thy [ntrunc_def]
clasohm@923
   415
    "(!!k. ntrunc k M <= N) ==> M<=N";
clasohm@923
   416
by (fast_tac (set_cs addIs [less_add_Suc1, less_add_Suc2, 
clasohm@923
   417
			    major RS subsetD]) 1);
clasohm@923
   418
qed "ntrunc_subsetD";
clasohm@923
   419
clasohm@923
   420
(*A generalized form of the take-lemma*)
clasohm@923
   421
val [major] = goal Univ.thy "(!!k. ntrunc k M = ntrunc k N) ==> M=N";
clasohm@923
   422
by (rtac equalityI 1);
clasohm@923
   423
by (ALLGOALS (rtac ntrunc_subsetD));
clasohm@923
   424
by (ALLGOALS (rtac (ntrunc_subsetI RSN (2, subset_trans))));
clasohm@923
   425
by (rtac (major RS equalityD1) 1);
clasohm@923
   426
by (rtac (major RS equalityD2) 1);
clasohm@923
   427
qed "ntrunc_equality";
clasohm@923
   428
clasohm@923
   429
val [major] = goalw Univ.thy [o_def]
clasohm@923
   430
    "[| !!k. (ntrunc(k) o h1) = (ntrunc(k) o h2) |] ==> h1=h2";
clasohm@923
   431
by (rtac (ntrunc_equality RS ext) 1);
clasohm@923
   432
by (rtac (major RS fun_cong) 1);
clasohm@923
   433
qed "ntrunc_o_equality";
clasohm@923
   434
clasohm@923
   435
(*** Monotonicity ***)
clasohm@923
   436
clasohm@923
   437
goalw Univ.thy [uprod_def] "!!A B. [| A<=A';  B<=B' |] ==> A<*>B <= A'<*>B'";
clasohm@923
   438
by (fast_tac set_cs 1);
clasohm@923
   439
qed "uprod_mono";
clasohm@923
   440
clasohm@923
   441
goalw Univ.thy [usum_def] "!!A B. [| A<=A';  B<=B' |] ==> A<+>B <= A'<+>B'";
clasohm@923
   442
by (fast_tac set_cs 1);
clasohm@923
   443
qed "usum_mono";
clasohm@923
   444
clasohm@923
   445
goalw Univ.thy [Scons_def] "!!M N. [| M<=M';  N<=N' |] ==> M$N <= M'$N'";
clasohm@923
   446
by (fast_tac set_cs 1);
clasohm@923
   447
qed "Scons_mono";
clasohm@923
   448
clasohm@923
   449
goalw Univ.thy [In0_def] "!!M N. M<=N ==> In0(M) <= In0(N)";
clasohm@923
   450
by (REPEAT (ares_tac [subset_refl,Scons_mono] 1));
clasohm@923
   451
qed "In0_mono";
clasohm@923
   452
clasohm@923
   453
goalw Univ.thy [In1_def] "!!M N. M<=N ==> In1(M) <= In1(N)";
clasohm@923
   454
by (REPEAT (ares_tac [subset_refl,Scons_mono] 1));
clasohm@923
   455
qed "In1_mono";
clasohm@923
   456
clasohm@923
   457
clasohm@923
   458
(*** Split and Case ***)
clasohm@923
   459
clasohm@923
   460
goalw Univ.thy [Split_def] "Split c (M$N) = c M N";
clasohm@923
   461
by (fast_tac (set_cs addIs [select_equality] addEs [Scons_inject]) 1);
clasohm@923
   462
qed "Split";
clasohm@923
   463
clasohm@923
   464
goalw Univ.thy [Case_def] "Case c d (In0 M) = c(M)";
clasohm@923
   465
by (fast_tac (set_cs addIs [select_equality] 
clasohm@923
   466
		     addEs [make_elim In0_inject, In0_neq_In1]) 1);
clasohm@923
   467
qed "Case_In0";
clasohm@923
   468
clasohm@923
   469
goalw Univ.thy [Case_def] "Case c d (In1 N) = d(N)";
clasohm@923
   470
by (fast_tac (set_cs addIs [select_equality] 
clasohm@923
   471
		     addEs [make_elim In1_inject, In1_neq_In0]) 1);
clasohm@923
   472
qed "Case_In1";
clasohm@923
   473
clasohm@923
   474
(**** UN x. B(x) rules ****)
clasohm@923
   475
clasohm@923
   476
goalw Univ.thy [ntrunc_def] "ntrunc k (UN x.f(x)) = (UN x. ntrunc k (f x))";
clasohm@923
   477
by (fast_tac (set_cs addIs [equalityI]) 1);
clasohm@923
   478
qed "ntrunc_UN1";
clasohm@923
   479
clasohm@923
   480
goalw Univ.thy [Scons_def] "(UN x.f(x)) $ M = (UN x. f(x) $ M)";
clasohm@923
   481
by (fast_tac (set_cs addIs [equalityI]) 1);
clasohm@923
   482
qed "Scons_UN1_x";
clasohm@923
   483
clasohm@923
   484
goalw Univ.thy [Scons_def] "M $ (UN x.f(x)) = (UN x. M $ f(x))";
clasohm@923
   485
by (fast_tac (set_cs addIs [equalityI]) 1);
clasohm@923
   486
qed "Scons_UN1_y";
clasohm@923
   487
clasohm@923
   488
goalw Univ.thy [In0_def] "In0(UN x.f(x)) = (UN x. In0(f(x)))";
clasohm@923
   489
br Scons_UN1_y 1;
clasohm@923
   490
qed "In0_UN1";
clasohm@923
   491
clasohm@923
   492
goalw Univ.thy [In1_def] "In1(UN x.f(x)) = (UN x. In1(f(x)))";
clasohm@923
   493
br Scons_UN1_y 1;
clasohm@923
   494
qed "In1_UN1";
clasohm@923
   495
clasohm@923
   496
clasohm@923
   497
(*** Equality : the diagonal relation ***)
clasohm@923
   498
clasohm@923
   499
goalw Univ.thy [diag_def] "!!a A. [| a=b;  a:A |] ==> <a,b> : diag(A)";
clasohm@923
   500
by (fast_tac set_cs 1);
clasohm@923
   501
qed "diag_eqI";
clasohm@923
   502
clasohm@923
   503
val diagI = refl RS diag_eqI |> standard;
clasohm@923
   504
clasohm@923
   505
(*The general elimination rule*)
clasohm@923
   506
val major::prems = goalw Univ.thy [diag_def]
clasohm@923
   507
    "[| c : diag(A);  \
clasohm@923
   508
\       !!x y. [| x:A;  c = <x,x> |] ==> P \
clasohm@923
   509
\    |] ==> P";
clasohm@923
   510
by (rtac (major RS UN_E) 1);
clasohm@923
   511
by (REPEAT (eresolve_tac [asm_rl,singletonE] 1 ORELSE resolve_tac prems 1));
clasohm@923
   512
qed "diagE";
clasohm@923
   513
clasohm@923
   514
(*** Equality for Cartesian Product ***)
clasohm@923
   515
clasohm@923
   516
goalw Univ.thy [dprod_def]
clasohm@923
   517
    "!!r s. [| <M,M'>:r;  <N,N'>:s |] ==> <M$N, M'$N'> : r<**>s";
clasohm@923
   518
by (fast_tac prod_cs 1);
clasohm@923
   519
qed "dprodI";
clasohm@923
   520
clasohm@923
   521
(*The general elimination rule*)
clasohm@923
   522
val major::prems = goalw Univ.thy [dprod_def]
clasohm@923
   523
    "[| c : r<**>s;  \
clasohm@923
   524
\       !!x y x' y'. [| <x,x'> : r;  <y,y'> : s;  c = <x$y,x'$y'> |] ==> P \
clasohm@923
   525
\    |] ==> P";
clasohm@923
   526
by (cut_facts_tac [major] 1);
clasohm@923
   527
by (REPEAT_FIRST (eresolve_tac [asm_rl, UN_E, mem_splitE, singletonE]));
clasohm@923
   528
by (REPEAT (ares_tac prems 1 ORELSE hyp_subst_tac 1));
clasohm@923
   529
qed "dprodE";
clasohm@923
   530
clasohm@923
   531
clasohm@923
   532
(*** Equality for Disjoint Sum ***)
clasohm@923
   533
clasohm@923
   534
goalw Univ.thy [dsum_def]  "!!r. <M,M'>:r ==> <In0(M), In0(M')> : r<++>s";
clasohm@923
   535
by (fast_tac prod_cs 1);
clasohm@923
   536
qed "dsum_In0I";
clasohm@923
   537
clasohm@923
   538
goalw Univ.thy [dsum_def]  "!!r. <N,N'>:s ==> <In1(N), In1(N')> : r<++>s";
clasohm@923
   539
by (fast_tac prod_cs 1);
clasohm@923
   540
qed "dsum_In1I";
clasohm@923
   541
clasohm@923
   542
val major::prems = goalw Univ.thy [dsum_def]
clasohm@923
   543
    "[| w : r<++>s;  \
clasohm@923
   544
\       !!x x'. [| <x,x'> : r;  w = <In0(x), In0(x')> |] ==> P; \
clasohm@923
   545
\       !!y y'. [| <y,y'> : s;  w = <In1(y), In1(y')> |] ==> P \
clasohm@923
   546
\    |] ==> P";
clasohm@923
   547
by (cut_facts_tac [major] 1);
clasohm@923
   548
by (REPEAT_FIRST (eresolve_tac [asm_rl, UN_E, UnE, mem_splitE, singletonE]));
clasohm@923
   549
by (DEPTH_SOLVE (ares_tac prems 1 ORELSE hyp_subst_tac 1));
clasohm@923
   550
qed "dsumE";
clasohm@923
   551
clasohm@923
   552
clasohm@923
   553
val univ_cs =
clasohm@923
   554
    prod_cs addSIs [diagI, uprodI, dprodI]
clasohm@923
   555
            addIs  [usum_In0I, usum_In1I, dsum_In0I, dsum_In1I]
clasohm@923
   556
            addSEs [diagE, uprodE, dprodE, usumE, dsumE];
clasohm@923
   557
clasohm@923
   558
clasohm@923
   559
(*** Monotonicity ***)
clasohm@923
   560
clasohm@923
   561
goal Univ.thy "!!r s. [| r<=r';  s<=s' |] ==> r<**>s <= r'<**>s'";
clasohm@923
   562
by (fast_tac univ_cs 1);
clasohm@923
   563
qed "dprod_mono";
clasohm@923
   564
clasohm@923
   565
goal Univ.thy "!!r s. [| r<=r';  s<=s' |] ==> r<++>s <= r'<++>s'";
clasohm@923
   566
by (fast_tac univ_cs 1);
clasohm@923
   567
qed "dsum_mono";
clasohm@923
   568
clasohm@923
   569
clasohm@923
   570
(*** Bounding theorems ***)
clasohm@923
   571
clasohm@923
   572
goal Univ.thy "diag(A) <= Sigma A (%x.A)";
clasohm@923
   573
by (fast_tac univ_cs 1);
clasohm@923
   574
qed "diag_subset_Sigma";
clasohm@923
   575
clasohm@923
   576
goal Univ.thy "(Sigma A (%x.B) <**> Sigma C (%x.D)) <= Sigma (A<*>C) (%z. B<*>D)";
clasohm@923
   577
by (fast_tac univ_cs 1);
clasohm@923
   578
qed "dprod_Sigma";
clasohm@923
   579
clasohm@923
   580
val dprod_subset_Sigma = [dprod_mono, dprod_Sigma] MRS subset_trans |>standard;
clasohm@923
   581
clasohm@923
   582
(*Dependent version*)
clasohm@923
   583
goal Univ.thy
clasohm@923
   584
    "(Sigma A B <**> Sigma C D) <= Sigma (A<*>C) (Split(%x y. B(x)<*>D(y)))";
clasohm@923
   585
by (safe_tac univ_cs);
clasohm@923
   586
by (stac Split 1);
clasohm@923
   587
by (fast_tac univ_cs 1);
clasohm@923
   588
qed "dprod_subset_Sigma2";
clasohm@923
   589
clasohm@923
   590
goal Univ.thy "(Sigma A (%x.B) <++> Sigma C (%x.D)) <= Sigma (A<+>C) (%z. B<+>D)";
clasohm@923
   591
by (fast_tac univ_cs 1);
clasohm@923
   592
qed "dsum_Sigma";
clasohm@923
   593
clasohm@923
   594
val dsum_subset_Sigma = [dsum_mono, dsum_Sigma] MRS subset_trans |> standard;
clasohm@923
   595
clasohm@923
   596
clasohm@923
   597
(*** Domain ***)
clasohm@923
   598
clasohm@923
   599
goal Univ.thy "fst `` diag(A) = A";
clasohm@923
   600
by (fast_tac (prod_cs addIs [equalityI, diagI] addSEs [diagE]) 1);
clasohm@923
   601
qed "fst_image_diag";
clasohm@923
   602
clasohm@923
   603
goal Univ.thy "fst `` (r<**>s) = (fst``r) <*> (fst``s)";
clasohm@923
   604
by (fast_tac (prod_cs addIs [equalityI, uprodI, dprodI]
clasohm@923
   605
                     addSEs [uprodE, dprodE]) 1);
clasohm@923
   606
qed "fst_image_dprod";
clasohm@923
   607
clasohm@923
   608
goal Univ.thy "fst `` (r<++>s) = (fst``r) <+> (fst``s)";
clasohm@923
   609
by (fast_tac (prod_cs addIs [equalityI, usum_In0I, usum_In1I, 
clasohm@923
   610
			     dsum_In0I, dsum_In1I]
clasohm@923
   611
                     addSEs [usumE, dsumE]) 1);
clasohm@923
   612
qed "fst_image_dsum";
clasohm@923
   613
clasohm@923
   614
val fst_image_simps = [fst_image_diag, fst_image_dprod, fst_image_dsum];
clasohm@923
   615
val fst_image_ss = univ_ss addsimps fst_image_simps;