src/HOL/Datatype_Universe.ML
author wenzelm
Tue Jan 16 00:29:43 2001 +0100 (2001-01-16)
changeset 10908 a7cfffb5d7dc
parent 10850 e1a793957a8f
child 11464 ddea204de5bc
permissions -rw-r--r--
renamed Abs_Node_inject to Abs_Node_inj;
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@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);
wenzelm@10908
    87
by (REPEAT (eresolve_tac [imageE, Abs_Node_inj 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)";
wenzelm@10908
    99
by (blast_tac (claset() addSIs [injI, Node_K0_I] addSDs [Abs_Node_inj]) 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";
wenzelm@10908
   129
by (rtac (major RS Abs_Node_inj 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";
wenzelm@10908
   210
by (EVERY1[stac (Node_K0_I RS Abs_Node_inverse), stac split_conv]);
nipkow@10213
   211
by (rtac Least_equality 1);
paulson@10850
   212
by Auto_tac;  
nipkow@10213
   213
qed "ndepth_K0";
nipkow@10213
   214
paulson@10850
   215
Goal "nat_case (Inr (Suc i)) f k = Inr 0 --> Suc(LEAST x. f x = Inr 0) <= k";
nipkow@10213
   216
by (induct_tac "k" 1);
nipkow@10213
   217
by (ALLGOALS Simp_tac);
paulson@10850
   218
by (rtac impI 1); 
paulson@10850
   219
by (etac Least_le 1);
nipkow@10213
   220
val lemma = result();
nipkow@10213
   221
nipkow@10213
   222
Goalw [ndepth_def,Push_Node_def]
nipkow@10213
   223
    "ndepth (Push_Node (Inr (Suc i)) n) = Suc(ndepth(n))";
nipkow@10213
   224
by (stac (Rep_Node RS Node_Push_I RS Abs_Node_inverse) 1);
nipkow@10213
   225
by (cut_facts_tac [rewrite_rule [Node_def] Rep_Node] 1);
nipkow@10213
   226
by Safe_tac;
nipkow@10213
   227
by (etac ssubst 1);  (*instantiates type variables!*)
nipkow@10213
   228
by (Simp_tac 1);
nipkow@10213
   229
by (rtac Least_equality 1);
nipkow@10213
   230
by (rewtac Push_def);
paulson@10850
   231
by (auto_tac (claset(), simpset() addsimps [lemma]));  
nipkow@10213
   232
by (etac LeastI 1);
nipkow@10213
   233
qed "ndepth_Push_Node";
nipkow@10213
   234
nipkow@10213
   235
nipkow@10213
   236
(*** ntrunc applied to the various node sets ***)
nipkow@10213
   237
nipkow@10213
   238
Goalw [ntrunc_def] "ntrunc 0 M = {}";
nipkow@10213
   239
by (Blast_tac 1);
nipkow@10213
   240
qed "ntrunc_0";
nipkow@10213
   241
nipkow@10213
   242
Goalw [Atom_def,ntrunc_def] "ntrunc (Suc k) (Atom a) = Atom(a)";
nipkow@10213
   243
by (fast_tac (claset() addss (simpset() addsimps [ndepth_K0])) 1);
nipkow@10213
   244
qed "ntrunc_Atom";
nipkow@10213
   245
nipkow@10213
   246
Goalw [Leaf_def,o_def] "ntrunc (Suc k) (Leaf a) = Leaf(a)";
nipkow@10213
   247
by (rtac ntrunc_Atom 1);
nipkow@10213
   248
qed "ntrunc_Leaf";
nipkow@10213
   249
nipkow@10213
   250
Goalw [Numb_def,o_def] "ntrunc (Suc k) (Numb i) = Numb(i)";
nipkow@10213
   251
by (rtac ntrunc_Atom 1);
nipkow@10213
   252
qed "ntrunc_Numb";
nipkow@10213
   253
nipkow@10213
   254
Goalw [Scons_def,ntrunc_def]
nipkow@10213
   255
    "ntrunc (Suc k) (Scons M N) = Scons (ntrunc k M) (ntrunc k N)";
nipkow@10213
   256
by (safe_tac (claset() addSIs [imageI]));
nipkow@10213
   257
by (REPEAT (stac ndepth_Push_Node 3 THEN etac Suc_mono 3));
nipkow@10213
   258
by (REPEAT (rtac Suc_less_SucD 1 THEN 
nipkow@10213
   259
            rtac (ndepth_Push_Node RS subst) 1 THEN 
nipkow@10213
   260
            assume_tac 1));
nipkow@10213
   261
qed "ntrunc_Scons";
nipkow@10213
   262
nipkow@10213
   263
Addsimps [ntrunc_0, ntrunc_Atom, ntrunc_Leaf, ntrunc_Numb, ntrunc_Scons];
nipkow@10213
   264
nipkow@10213
   265
nipkow@10213
   266
(** Injection nodes **)
nipkow@10213
   267
nipkow@10213
   268
Goalw [In0_def] "ntrunc 1 (In0 M) = {}";
nipkow@10213
   269
by (Simp_tac 1);
nipkow@10213
   270
by (rewtac Scons_def);
nipkow@10213
   271
by (Blast_tac 1);
nipkow@10213
   272
qed "ntrunc_one_In0";
nipkow@10213
   273
nipkow@10213
   274
Goalw [In0_def]
nipkow@10213
   275
    "ntrunc (Suc (Suc k)) (In0 M) = In0 (ntrunc (Suc k) M)";
nipkow@10213
   276
by (Simp_tac 1);
nipkow@10213
   277
qed "ntrunc_In0";
nipkow@10213
   278
nipkow@10213
   279
Goalw [In1_def] "ntrunc 1 (In1 M) = {}";
nipkow@10213
   280
by (Simp_tac 1);
nipkow@10213
   281
by (rewtac Scons_def);
nipkow@10213
   282
by (Blast_tac 1);
nipkow@10213
   283
qed "ntrunc_one_In1";
nipkow@10213
   284
nipkow@10213
   285
Goalw [In1_def]
nipkow@10213
   286
    "ntrunc (Suc (Suc k)) (In1 M) = In1 (ntrunc (Suc k) M)";
nipkow@10213
   287
by (Simp_tac 1);
nipkow@10213
   288
qed "ntrunc_In1";
nipkow@10213
   289
nipkow@10213
   290
Addsimps [ntrunc_one_In0, ntrunc_In0, ntrunc_one_In1, ntrunc_In1];
nipkow@10213
   291
nipkow@10213
   292
nipkow@10213
   293
(*** Cartesian Product ***)
nipkow@10213
   294
nipkow@10213
   295
Goalw [uprod_def] "[| M:A;  N:B |] ==> Scons M N : uprod A B";
nipkow@10213
   296
by (REPEAT (ares_tac [singletonI,UN_I] 1));
nipkow@10213
   297
qed "uprodI";
nipkow@10213
   298
nipkow@10213
   299
(*The general elimination rule*)
nipkow@10213
   300
val major::prems = Goalw [uprod_def]
nipkow@10213
   301
    "[| c : uprod A B;  \
nipkow@10213
   302
\       !!x y. [| x:A;  y:B;  c = Scons x y |] ==> P \
nipkow@10213
   303
\    |] ==> P";
nipkow@10213
   304
by (cut_facts_tac [major] 1);
nipkow@10213
   305
by (REPEAT (eresolve_tac [asm_rl,singletonE,UN_E] 1
nipkow@10213
   306
     ORELSE resolve_tac prems 1));
nipkow@10213
   307
qed "uprodE";
nipkow@10213
   308
nipkow@10213
   309
(*Elimination of a pair -- introduces no eigenvariables*)
nipkow@10213
   310
val prems = Goal
nipkow@10213
   311
    "[| Scons M N : uprod A B;      [| M:A;  N:B |] ==> P   \
nipkow@10213
   312
\    |] ==> P";
nipkow@10213
   313
by (rtac uprodE 1);
nipkow@10213
   314
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Scons_inject,ssubst] 1));
nipkow@10213
   315
qed "uprodE2";
nipkow@10213
   316
nipkow@10213
   317
nipkow@10213
   318
(*** Disjoint Sum ***)
nipkow@10213
   319
nipkow@10213
   320
Goalw [usum_def] "M:A ==> In0(M) : usum A B";
nipkow@10213
   321
by (Blast_tac 1);
nipkow@10213
   322
qed "usum_In0I";
nipkow@10213
   323
nipkow@10213
   324
Goalw [usum_def] "N:B ==> In1(N) : usum A B";
nipkow@10213
   325
by (Blast_tac 1);
nipkow@10213
   326
qed "usum_In1I";
nipkow@10213
   327
nipkow@10213
   328
val major::prems = Goalw [usum_def]
nipkow@10213
   329
    "[| u : usum A B;  \
nipkow@10213
   330
\       !!x. [| x:A;  u=In0(x) |] ==> P; \
nipkow@10213
   331
\       !!y. [| y:B;  u=In1(y) |] ==> P \
nipkow@10213
   332
\    |] ==> P";
nipkow@10213
   333
by (rtac (major RS UnE) 1);
nipkow@10213
   334
by (REPEAT (rtac refl 1 
nipkow@10213
   335
     ORELSE eresolve_tac (prems@[imageE,ssubst]) 1));
nipkow@10213
   336
qed "usumE";
nipkow@10213
   337
nipkow@10213
   338
nipkow@10213
   339
(** Injection **)
nipkow@10213
   340
nipkow@10213
   341
Goalw [In0_def,In1_def] "In0(M) ~= In1(N)";
nipkow@10213
   342
by (rtac notI 1);
nipkow@10213
   343
by (etac (Scons_inject1 RS Numb_inject RS Zero_neq_Suc) 1);
nipkow@10213
   344
qed "In0_not_In1";
nipkow@10213
   345
nipkow@10213
   346
bind_thm ("In1_not_In0", In0_not_In1 RS not_sym);
nipkow@10213
   347
nipkow@10213
   348
AddIffs [In0_not_In1, In1_not_In0];
nipkow@10213
   349
nipkow@10213
   350
Goalw [In0_def] "In0(M) = In0(N) ==>  M=N";
nipkow@10213
   351
by (etac (Scons_inject2) 1);
nipkow@10213
   352
qed "In0_inject";
nipkow@10213
   353
nipkow@10213
   354
Goalw [In1_def] "In1(M) = In1(N) ==>  M=N";
nipkow@10213
   355
by (etac (Scons_inject2) 1);
nipkow@10213
   356
qed "In1_inject";
nipkow@10213
   357
nipkow@10213
   358
Goal "(In0 M = In0 N) = (M=N)";
nipkow@10213
   359
by (blast_tac (claset() addSDs [In0_inject]) 1);
nipkow@10213
   360
qed "In0_eq";
nipkow@10213
   361
nipkow@10213
   362
Goal "(In1 M = In1 N) = (M=N)";
nipkow@10213
   363
by (blast_tac (claset() addSDs [In1_inject]) 1);
nipkow@10213
   364
qed "In1_eq";
nipkow@10213
   365
nipkow@10213
   366
AddIffs [In0_eq, In1_eq];
nipkow@10213
   367
nipkow@10213
   368
Goal "inj In0";
nipkow@10213
   369
by (blast_tac (claset() addSIs [injI]) 1);
nipkow@10213
   370
qed "inj_In0";
nipkow@10213
   371
nipkow@10213
   372
Goal "inj In1";
nipkow@10213
   373
by (blast_tac (claset() addSIs [injI]) 1);
nipkow@10213
   374
qed "inj_In1";
nipkow@10213
   375
nipkow@10213
   376
nipkow@10213
   377
(*** Function spaces ***)
nipkow@10213
   378
nipkow@10213
   379
Goalw [Lim_def] "Lim f = Lim g ==> f = g";
nipkow@10213
   380
by (rtac ext 1);
nipkow@10213
   381
by (blast_tac (claset() addSEs [Push_Node_inject]) 1);
nipkow@10213
   382
qed "Lim_inject";
nipkow@10213
   383
nipkow@10213
   384
Goalw [Funs_def] "S <= T ==> Funs S <= Funs T";
nipkow@10213
   385
by (Blast_tac 1);
nipkow@10213
   386
qed "Funs_mono";
nipkow@10213
   387
nipkow@10213
   388
val [prem] = Goalw [Funs_def] "(!!x. f x : S) ==> f : Funs S";
nipkow@10213
   389
by (blast_tac (claset() addIs [prem]) 1);
nipkow@10213
   390
qed "FunsI";
nipkow@10213
   391
nipkow@10213
   392
Goalw [Funs_def] "f : Funs S ==> f x : S";
nipkow@10213
   393
by (etac CollectE 1);
nipkow@10213
   394
by (etac subsetD 1);
nipkow@10213
   395
by (rtac rangeI 1);
nipkow@10213
   396
qed "FunsD";
nipkow@10213
   397
nipkow@10213
   398
val [p1, p2] = Goalw [o_def]
nipkow@10213
   399
   "[| f : Funs R; !!x. x : R ==> r (a x) = x |] ==> r o (a o f) = f";
nipkow@10213
   400
by (rtac (p2 RS ext) 1);
nipkow@10213
   401
by (rtac (p1 RS FunsD) 1);
nipkow@10213
   402
qed "Funs_inv";
nipkow@10213
   403
nipkow@10213
   404
val [p1, p2] = Goalw [o_def]
nipkow@10213
   405
     "[| f : Funs (range g); !!h. f = g o h ==> P |] ==> P";
nipkow@10213
   406
by (res_inst_tac [("h", "%x. @y. (f::'a=>'b) x = g y")] p2 1);
nipkow@10213
   407
by (rtac ext 1);
nipkow@10213
   408
by (rtac (p1 RS FunsD RS rangeE) 1);
nipkow@10213
   409
by (etac (exI RS (some_eq_ex RS iffD2)) 1);
nipkow@10213
   410
qed "Funs_rangeE";
nipkow@10213
   411
nipkow@10213
   412
Goal "a : S ==> (%x. a) : Funs S";
nipkow@10213
   413
by (rtac FunsI 1);
nipkow@10213
   414
by (assume_tac 1);
nipkow@10213
   415
qed "Funs_nonempty";
nipkow@10213
   416
nipkow@10213
   417
nipkow@10213
   418
(*** proving equality of sets and functions using ntrunc ***)
nipkow@10213
   419
nipkow@10213
   420
Goalw [ntrunc_def] "ntrunc k M <= M";
nipkow@10213
   421
by (Blast_tac 1);
nipkow@10213
   422
qed "ntrunc_subsetI";
nipkow@10213
   423
nipkow@10213
   424
val [major] = Goalw [ntrunc_def] "(!!k. ntrunc k M <= N) ==> M<=N";
nipkow@10213
   425
by (blast_tac (claset() addIs [less_add_Suc1, less_add_Suc2, 
nipkow@10213
   426
			       major RS subsetD]) 1);
nipkow@10213
   427
qed "ntrunc_subsetD";
nipkow@10213
   428
nipkow@10213
   429
(*A generalized form of the take-lemma*)
nipkow@10213
   430
val [major] = Goal "(!!k. ntrunc k M = ntrunc k N) ==> M=N";
nipkow@10213
   431
by (rtac equalityI 1);
nipkow@10213
   432
by (ALLGOALS (rtac ntrunc_subsetD));
nipkow@10213
   433
by (ALLGOALS (rtac (ntrunc_subsetI RSN (2, subset_trans))));
nipkow@10213
   434
by (rtac (major RS equalityD1) 1);
nipkow@10213
   435
by (rtac (major RS equalityD2) 1);
nipkow@10213
   436
qed "ntrunc_equality";
nipkow@10213
   437
nipkow@10213
   438
val [major] = Goalw [o_def]
nipkow@10213
   439
    "[| !!k. (ntrunc(k) o h1) = (ntrunc(k) o h2) |] ==> h1=h2";
nipkow@10213
   440
by (rtac (ntrunc_equality RS ext) 1);
nipkow@10213
   441
by (rtac (major RS fun_cong) 1);
nipkow@10213
   442
qed "ntrunc_o_equality";
nipkow@10213
   443
nipkow@10213
   444
(*** Monotonicity ***)
nipkow@10213
   445
nipkow@10213
   446
Goalw [uprod_def] "[| A<=A';  B<=B' |] ==> uprod A B <= uprod A' B'";
nipkow@10213
   447
by (Blast_tac 1);
nipkow@10213
   448
qed "uprod_mono";
nipkow@10213
   449
nipkow@10213
   450
Goalw [usum_def] "[| A<=A';  B<=B' |] ==> usum A B <= usum A' B'";
nipkow@10213
   451
by (Blast_tac 1);
nipkow@10213
   452
qed "usum_mono";
nipkow@10213
   453
nipkow@10213
   454
Goalw [Scons_def] "[| M<=M';  N<=N' |] ==> Scons M N <= Scons M' N'";
nipkow@10213
   455
by (Blast_tac 1);
nipkow@10213
   456
qed "Scons_mono";
nipkow@10213
   457
nipkow@10213
   458
Goalw [In0_def] "M<=N ==> In0(M) <= In0(N)";
nipkow@10213
   459
by (REPEAT (ares_tac [subset_refl,Scons_mono] 1));
nipkow@10213
   460
qed "In0_mono";
nipkow@10213
   461
nipkow@10213
   462
Goalw [In1_def] "M<=N ==> In1(M) <= In1(N)";
nipkow@10213
   463
by (REPEAT (ares_tac [subset_refl,Scons_mono] 1));
nipkow@10213
   464
qed "In1_mono";
nipkow@10213
   465
nipkow@10213
   466
nipkow@10213
   467
(*** Split and Case ***)
nipkow@10213
   468
nipkow@10213
   469
Goalw [Split_def] "Split c (Scons M N) = c M N";
nipkow@10213
   470
by (Blast_tac  1);
nipkow@10213
   471
qed "Split";
nipkow@10213
   472
nipkow@10213
   473
Goalw [Case_def] "Case c d (In0 M) = c(M)";
nipkow@10213
   474
by (Blast_tac 1);
nipkow@10213
   475
qed "Case_In0";
nipkow@10213
   476
nipkow@10213
   477
Goalw [Case_def] "Case c d (In1 N) = d(N)";
nipkow@10213
   478
by (Blast_tac 1);
nipkow@10213
   479
qed "Case_In1";
nipkow@10213
   480
nipkow@10213
   481
Addsimps [Split, Case_In0, Case_In1];
nipkow@10213
   482
nipkow@10213
   483
nipkow@10213
   484
(**** UN x. B(x) rules ****)
nipkow@10213
   485
nipkow@10213
   486
Goalw [ntrunc_def] "ntrunc k (UN x. f(x)) = (UN x. ntrunc k (f x))";
nipkow@10213
   487
by (Blast_tac 1);
nipkow@10213
   488
qed "ntrunc_UN1";
nipkow@10213
   489
nipkow@10213
   490
Goalw [Scons_def] "Scons (UN x. f x) M = (UN x. Scons (f x) M)";
nipkow@10213
   491
by (Blast_tac 1);
nipkow@10213
   492
qed "Scons_UN1_x";
nipkow@10213
   493
nipkow@10213
   494
Goalw [Scons_def] "Scons M (UN x. f x) = (UN x. Scons M (f x))";
nipkow@10213
   495
by (Blast_tac 1);
nipkow@10213
   496
qed "Scons_UN1_y";
nipkow@10213
   497
nipkow@10213
   498
Goalw [In0_def] "In0(UN x. f(x)) = (UN x. In0(f(x)))";
nipkow@10213
   499
by (rtac Scons_UN1_y 1);
nipkow@10213
   500
qed "In0_UN1";
nipkow@10213
   501
nipkow@10213
   502
Goalw [In1_def] "In1(UN x. f(x)) = (UN x. In1(f(x)))";
nipkow@10213
   503
by (rtac Scons_UN1_y 1);
nipkow@10213
   504
qed "In1_UN1";
nipkow@10213
   505
nipkow@10213
   506
nipkow@10213
   507
(*** Equality for Cartesian Product ***)
nipkow@10213
   508
nipkow@10213
   509
Goalw [dprod_def]
nipkow@10213
   510
    "[| (M,M'):r;  (N,N'):s |] ==> (Scons M N, Scons M' N') : dprod r s";
nipkow@10213
   511
by (Blast_tac 1);
nipkow@10213
   512
qed "dprodI";
nipkow@10213
   513
nipkow@10213
   514
(*The general elimination rule*)
nipkow@10213
   515
val major::prems = Goalw [dprod_def]
nipkow@10213
   516
    "[| c : dprod r s;  \
nipkow@10213
   517
\       !!x y x' y'. [| (x,x') : r;  (y,y') : s;  c = (Scons x y, Scons x' y') |] ==> P \
nipkow@10213
   518
\    |] ==> P";
nipkow@10213
   519
by (cut_facts_tac [major] 1);
nipkow@10213
   520
by (REPEAT_FIRST (eresolve_tac [asm_rl, UN_E, mem_splitE, singletonE]));
nipkow@10213
   521
by (REPEAT (ares_tac prems 1 ORELSE hyp_subst_tac 1));
nipkow@10213
   522
qed "dprodE";
nipkow@10213
   523
nipkow@10213
   524
nipkow@10213
   525
(*** Equality for Disjoint Sum ***)
nipkow@10213
   526
nipkow@10213
   527
Goalw [dsum_def]  "(M,M'):r ==> (In0(M), In0(M')) : dsum r s";
nipkow@10213
   528
by (Blast_tac 1);
nipkow@10213
   529
qed "dsum_In0I";
nipkow@10213
   530
nipkow@10213
   531
Goalw [dsum_def]  "(N,N'):s ==> (In1(N), In1(N')) : dsum r s";
nipkow@10213
   532
by (Blast_tac 1);
nipkow@10213
   533
qed "dsum_In1I";
nipkow@10213
   534
nipkow@10213
   535
val major::prems = Goalw [dsum_def]
nipkow@10213
   536
    "[| w : dsum r s;  \
nipkow@10213
   537
\       !!x x'. [| (x,x') : r;  w = (In0(x), In0(x')) |] ==> P; \
nipkow@10213
   538
\       !!y y'. [| (y,y') : s;  w = (In1(y), In1(y')) |] ==> P \
nipkow@10213
   539
\    |] ==> P";
nipkow@10213
   540
by (cut_facts_tac [major] 1);
nipkow@10213
   541
by (REPEAT_FIRST (eresolve_tac [asm_rl, UN_E, UnE, mem_splitE, singletonE]));
nipkow@10213
   542
by (DEPTH_SOLVE (ares_tac prems 1 ORELSE hyp_subst_tac 1));
nipkow@10213
   543
qed "dsumE";
nipkow@10213
   544
nipkow@10213
   545
AddSIs [uprodI, dprodI];
nipkow@10213
   546
AddIs  [usum_In0I, usum_In1I, dsum_In0I, dsum_In1I];
nipkow@10213
   547
AddSEs [uprodE, dprodE, usumE, dsumE];
nipkow@10213
   548
nipkow@10213
   549
nipkow@10213
   550
(*** Monotonicity ***)
nipkow@10213
   551
nipkow@10213
   552
Goal "[| r<=r';  s<=s' |] ==> dprod r s <= dprod r' s'";
nipkow@10213
   553
by (Blast_tac 1);
nipkow@10213
   554
qed "dprod_mono";
nipkow@10213
   555
nipkow@10213
   556
Goal "[| r<=r';  s<=s' |] ==> dsum r s <= dsum r' s'";
nipkow@10213
   557
by (Blast_tac 1);
nipkow@10213
   558
qed "dsum_mono";
nipkow@10213
   559
nipkow@10213
   560
nipkow@10213
   561
(*** Bounding theorems ***)
nipkow@10213
   562
nipkow@10213
   563
Goal "(dprod (A <*> B) (C <*> D)) <= (uprod A C) <*> (uprod B D)";
nipkow@10213
   564
by (Blast_tac 1);
nipkow@10213
   565
qed "dprod_Sigma";
nipkow@10213
   566
nipkow@10213
   567
bind_thm ("dprod_subset_Sigma", [dprod_mono, dprod_Sigma] MRS subset_trans |> standard);
nipkow@10213
   568
nipkow@10213
   569
(*Dependent version*)
nipkow@10213
   570
Goal "(dprod (Sigma A B) (Sigma C D)) <= Sigma (uprod A C) (Split (%x y. uprod (B x) (D y)))";
nipkow@10213
   571
by Safe_tac;
nipkow@10213
   572
by (stac Split 1);
nipkow@10213
   573
by (Blast_tac 1);
nipkow@10213
   574
qed "dprod_subset_Sigma2";
nipkow@10213
   575
nipkow@10213
   576
Goal "(dsum (A <*> B) (C <*> D)) <= (usum A C) <*> (usum B D)";
nipkow@10213
   577
by (Blast_tac 1);
nipkow@10213
   578
qed "dsum_Sigma";
nipkow@10213
   579
nipkow@10213
   580
bind_thm ("dsum_subset_Sigma", [dsum_mono, dsum_Sigma] MRS subset_trans |> standard);
nipkow@10213
   581
nipkow@10213
   582
nipkow@10213
   583
(*** Domain ***)
nipkow@10213
   584
nipkow@10213
   585
Goal "Domain (dprod r s) = uprod (Domain r) (Domain s)";
nipkow@10213
   586
by Auto_tac;
nipkow@10213
   587
qed "Domain_dprod";
nipkow@10213
   588
nipkow@10213
   589
Goal "Domain (dsum r s) = usum (Domain r) (Domain s)";
nipkow@10213
   590
by Auto_tac;
nipkow@10213
   591
qed "Domain_dsum";
nipkow@10213
   592
nipkow@10213
   593
Addsimps [Domain_dprod, Domain_dsum];