| 1465 |      1 | (*  Title:      HOL/ex/set.ML
 | 
| 969 |      2 |     ID:         $Id$
 | 
| 1465 |      3 |     Author:     Tobias Nipkow, Cambridge University Computer Laboratory
 | 
| 969 |      4 |     Copyright   1991  University of Cambridge
 | 
|  |      5 | 
 | 
|  |      6 | Cantor's Theorem; the Schroeder-Berstein Theorem.  
 | 
|  |      7 | *)
 | 
|  |      8 | 
 | 
|  |      9 | 
 | 
|  |     10 | writeln"File HOL/ex/set.";
 | 
|  |     11 | 
 | 
|  |     12 | (*** A unique fixpoint theorem --- fast/best/meson all fail ***)
 | 
|  |     13 | 
 | 
|  |     14 | val [prem] = goal HOL.thy "?!x.f(g(x))=x ==> ?!y.g(f(y))=y";
 | 
|  |     15 | by(EVERY1[rtac (prem RS ex1E), rtac ex1I, etac arg_cong,
 | 
|  |     16 |           rtac subst, atac, etac allE, rtac arg_cong, etac mp, etac arg_cong]);
 | 
|  |     17 | result();
 | 
|  |     18 | 
 | 
|  |     19 | (*** Cantor's Theorem: There is no surjection from a set to its powerset. ***)
 | 
|  |     20 | 
 | 
|  |     21 | goal Set.thy "~ (? f:: 'a=>'a set. ! S. ? x. f(x) = S)";
 | 
|  |     22 | (*requires best-first search because it is undirectional*)
 | 
| 1820 |     23 | by (best_tac (!claset addSEs [equalityCE]) 1);
 | 
| 969 |     24 | qed "cantor1";
 | 
|  |     25 | 
 | 
|  |     26 | (*This form displays the diagonal term*)
 | 
|  |     27 | goal Set.thy "! f:: 'a=>'a set. ! x. f(x) ~= ?S(f)";
 | 
| 1820 |     28 | by (best_tac (!claset addSEs [equalityCE]) 1);
 | 
| 969 |     29 | uresult();
 | 
|  |     30 | 
 | 
|  |     31 | (*This form exploits the set constructs*)
 | 
|  |     32 | goal Set.thy "?S ~: range(f :: 'a=>'a set)";
 | 
|  |     33 | by (rtac notI 1);
 | 
|  |     34 | by (etac rangeE 1);
 | 
|  |     35 | by (etac equalityCE 1);
 | 
|  |     36 | by (dtac CollectD 1);
 | 
|  |     37 | by (contr_tac 1);
 | 
|  |     38 | by (swap_res_tac [CollectI] 1);
 | 
|  |     39 | by (assume_tac 1);
 | 
|  |     40 | 
 | 
|  |     41 | choplev 0;
 | 
| 1820 |     42 | by (best_tac (!claset addSEs [equalityCE]) 1);
 | 
| 969 |     43 | 
 | 
|  |     44 | (*** The Schroder-Berstein Theorem ***)
 | 
|  |     45 | 
 | 
|  |     46 | val prems = goalw Lfp.thy [image_def] "inj(f) ==> Inv(f)``(f``X) = X";
 | 
|  |     47 | by (cut_facts_tac prems 1);
 | 
|  |     48 | by (rtac equalityI 1);
 | 
| 1820 |     49 | by (fast_tac (!claset addEs [Inv_f_f RS ssubst]) 1);
 | 
|  |     50 | by (fast_tac (!claset addEs [Inv_f_f RS ssubst]) 1);
 | 
| 969 |     51 | qed "inv_image_comp";
 | 
|  |     52 | 
 | 
| 1888 |     53 | goal Set.thy "!!f. f(a) ~: (f``X) ==> a~:X";
 | 
|  |     54 | by (Fast_tac 1);
 | 
| 969 |     55 | qed "contra_imageI";
 | 
|  |     56 | 
 | 
|  |     57 | goal Lfp.thy "(a ~: Compl(X)) = (a:X)";
 | 
| 1820 |     58 | by (Fast_tac 1);
 | 
| 969 |     59 | qed "not_Compl";
 | 
|  |     60 | 
 | 
|  |     61 | (*Lots of backtracking in this proof...*)
 | 
|  |     62 | val [compl,fg,Xa] = goal Lfp.thy
 | 
|  |     63 |     "[| Compl(f``X) = g``Compl(X);  f(a)=g(b);  a:X |] ==> b:X";
 | 
|  |     64 | by (EVERY1 [rtac (not_Compl RS subst), rtac contra_imageI,
 | 
| 1465 |     65 |             rtac (compl RS subst), rtac (fg RS subst), stac not_Compl,
 | 
|  |     66 |             rtac imageI, rtac Xa]);
 | 
| 969 |     67 | qed "disj_lemma";
 | 
|  |     68 | 
 | 
| 1888 |     69 | goalw Lfp.thy [image_def]
 | 
|  |     70 |     "range(%z. if z:X then f(z) else g(z)) = f``X Un g``Compl(X)";
 | 
|  |     71 | by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
 | 
|  |     72 | by (Fast_tac 1);
 | 
| 969 |     73 | qed "range_if_then_else";
 | 
|  |     74 | 
 | 
|  |     75 | goal Lfp.thy "a : X Un Compl(X)";
 | 
| 1820 |     76 | by (Fast_tac 1);
 | 
| 969 |     77 | qed "X_Un_Compl";
 | 
|  |     78 | 
 | 
|  |     79 | goalw Lfp.thy [surj_def] "surj(f) = (!a. a : range(f))";
 | 
| 1820 |     80 | by (fast_tac (!claset addEs [ssubst]) 1);
 | 
| 969 |     81 | qed "surj_iff_full_range";
 | 
|  |     82 | 
 | 
|  |     83 | val [compl] = goal Lfp.thy
 | 
|  |     84 |     "Compl(f``X) = g``Compl(X) ==> surj(%z. if z:X then f(z) else g(z))";
 | 
| 1487 |     85 | by (EVERY1[stac surj_iff_full_range, stac range_if_then_else,
 | 
|  |     86 |            stac (compl RS sym)]);
 | 
| 969 |     87 | by (rtac (X_Un_Compl RS allI) 1);
 | 
|  |     88 | qed "surj_if_then_else";
 | 
|  |     89 | 
 | 
|  |     90 | val [injf,injg,compl,bij] = goal Lfp.thy
 | 
|  |     91 |     "[| inj_onto f X;  inj_onto g (Compl X);  Compl(f``X) = g``Compl(X); \
 | 
|  |     92 | \       bij = (%z. if z:X then f(z) else g(z)) |] ==> \
 | 
|  |     93 | \       inj(bij) & surj(bij)";
 | 
|  |     94 | val f_eq_gE = make_elim (compl RS disj_lemma);
 | 
|  |     95 | by (rtac (bij RS ssubst) 1);
 | 
|  |     96 | by (rtac conjI 1);
 | 
|  |     97 | by (rtac (compl RS surj_if_then_else) 2);
 | 
|  |     98 | by (rewtac inj_def);
 | 
|  |     99 | by (cut_facts_tac [injf,injg] 1);
 | 
|  |    100 | by (EVERY1 [rtac allI, rtac allI, stac expand_if, rtac conjI, stac expand_if]);
 | 
| 1820 |    101 | by (fast_tac (!claset addEs  [inj_ontoD, sym RS f_eq_gE]) 1);
 | 
| 969 |    102 | by (stac expand_if 1);
 | 
| 1820 |    103 | by (fast_tac (!claset addEs  [inj_ontoD, f_eq_gE]) 1);
 | 
| 969 |    104 | qed "bij_if_then_else";
 | 
|  |    105 | 
 | 
|  |    106 | goal Lfp.thy "? X. X = Compl(g``Compl((f:: 'a=>'b)``X))";
 | 
|  |    107 | by (rtac exI 1);
 | 
|  |    108 | by (rtac lfp_Tarski 1);
 | 
|  |    109 | by (REPEAT (ares_tac [monoI, image_mono, Compl_anti_mono] 1));
 | 
|  |    110 | qed "decomposition";
 | 
|  |    111 | 
 | 
|  |    112 | val [injf,injg] = goal Lfp.thy
 | 
|  |    113 |    "[| inj(f:: 'a=>'b);  inj(g:: 'b=>'a) |] ==> \
 | 
|  |    114 | \   ? h:: 'a=>'b. inj(h) & surj(h)";
 | 
|  |    115 | by (rtac (decomposition RS exE) 1);
 | 
|  |    116 | by (rtac exI 1);
 | 
|  |    117 | by (rtac bij_if_then_else 1);
 | 
|  |    118 | by (EVERY [rtac refl 4, rtac (injf RS inj_imp) 1,
 | 
| 1465 |    119 |            rtac (injg RS inj_onto_Inv) 1]);
 | 
| 969 |    120 | by (EVERY1 [etac ssubst, stac double_complement, rtac subsetI,
 | 
| 1465 |    121 |             etac imageE, etac ssubst, rtac rangeI]);
 | 
| 969 |    122 | by (EVERY1 [etac ssubst, stac double_complement, 
 | 
| 1465 |    123 |             rtac (injg RS inv_image_comp RS sym)]);
 | 
| 969 |    124 | qed "schroeder_bernstein";
 | 
|  |    125 | 
 | 
|  |    126 | writeln"Reached end of file.";
 |