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