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