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