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