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