| 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 | 
 | 
| 4153 |     12 | context Lfp.thy;
 | 
| 2998 |     13 | 
 | 
| 4153 |     14 | (*Nice demonstration of blast_tac--and its limitations*)
 | 
| 2998 |     15 | goal Set.thy "!!S::'a set set. ALL x:S. ALL y:S. x<=y ==> EX z. S <= {z}";
 | 
| 4153 |     16 | (*for some unfathomable reason, UNIV_I increases the search space greatly*)
 | 
|  |     17 | by (blast_tac (claset() delrules [UNIV_I]) 1);
 | 
|  |     18 | result();
 | 
|  |     19 | 
 | 
| 4324 |     20 | (*variant of the benchmark above*)
 | 
|  |     21 | goal Set.thy "!!S. ALL x:S. Union(S) <= x ==> EX z. S <= {z}";
 | 
|  |     22 | by (blast_tac (claset() delrules [UNIV_I]) 1);
 | 
|  |     23 | (*just Blast_tac takes 27 seconds instead of 2.2*)
 | 
|  |     24 | result();
 | 
| 2998 |     25 | 
 | 
| 969 |     26 | (*** A unique fixpoint theorem --- fast/best/meson all fail ***)
 | 
|  |     27 | 
 | 
| 3842 |     28 | val [prem] = goal HOL.thy "?!x. f(g(x))=x ==> ?!y. g(f(y))=y";
 | 
| 2031 |     29 | by (EVERY1[rtac (prem RS ex1E), rtac ex1I, etac arg_cong,
 | 
| 969 |     30 |           rtac subst, atac, etac allE, rtac arg_cong, etac mp, etac arg_cong]);
 | 
|  |     31 | result();
 | 
|  |     32 | 
 | 
|  |     33 | (*** Cantor's Theorem: There is no surjection from a set to its powerset. ***)
 | 
|  |     34 | 
 | 
|  |     35 | goal Set.thy "~ (? f:: 'a=>'a set. ! S. ? x. f(x) = S)";
 | 
|  |     36 | (*requires best-first search because it is undirectional*)
 | 
| 4089 |     37 | by (best_tac (claset() addSEs [equalityCE]) 1);
 | 
| 969 |     38 | qed "cantor1";
 | 
|  |     39 | 
 | 
|  |     40 | (*This form displays the diagonal term*)
 | 
|  |     41 | goal Set.thy "! f:: 'a=>'a set. ! x. f(x) ~= ?S(f)";
 | 
| 4089 |     42 | by (best_tac (claset() addSEs [equalityCE]) 1);
 | 
| 969 |     43 | uresult();
 | 
|  |     44 | 
 | 
|  |     45 | (*This form exploits the set constructs*)
 | 
|  |     46 | goal Set.thy "?S ~: range(f :: 'a=>'a set)";
 | 
|  |     47 | by (rtac notI 1);
 | 
|  |     48 | by (etac rangeE 1);
 | 
|  |     49 | by (etac equalityCE 1);
 | 
|  |     50 | by (dtac CollectD 1);
 | 
|  |     51 | by (contr_tac 1);
 | 
|  |     52 | by (swap_res_tac [CollectI] 1);
 | 
|  |     53 | by (assume_tac 1);
 | 
|  |     54 | 
 | 
|  |     55 | choplev 0;
 | 
| 4089 |     56 | by (best_tac (claset() addSEs [equalityCE]) 1);
 | 
| 969 |     57 | 
 | 
|  |     58 | (*** The Schroder-Berstein Theorem ***)
 | 
|  |     59 | 
 | 
| 2935 |     60 | goalw Lfp.thy [image_def] "!!f. inj(f) ==> inv(f)``(f``X) = X";
 | 
| 969 |     61 | by (rtac equalityI 1);
 | 
| 4089 |     62 | by (fast_tac (claset() addEs [inv_f_f RS ssubst]) 1);
 | 
|  |     63 | by (fast_tac (claset() addEs [inv_f_f RS ssubst]) 1);
 | 
| 969 |     64 | qed "inv_image_comp";
 | 
|  |     65 | 
 | 
| 1888 |     66 | goal Set.thy "!!f. f(a) ~: (f``X) ==> a~:X";
 | 
| 2935 |     67 | by (Blast_tac 1);
 | 
| 969 |     68 | qed "contra_imageI";
 | 
|  |     69 | 
 | 
|  |     70 | goal Lfp.thy "(a ~: Compl(X)) = (a:X)";
 | 
| 2935 |     71 | by (Blast_tac 1);
 | 
| 969 |     72 | qed "not_Compl";
 | 
|  |     73 | 
 | 
|  |     74 | (*Lots of backtracking in this proof...*)
 | 
|  |     75 | val [compl,fg,Xa] = goal Lfp.thy
 | 
|  |     76 |     "[| Compl(f``X) = g``Compl(X);  f(a)=g(b);  a:X |] ==> b:X";
 | 
|  |     77 | by (EVERY1 [rtac (not_Compl RS subst), rtac contra_imageI,
 | 
| 1465 |     78 |             rtac (compl RS subst), rtac (fg RS subst), stac not_Compl,
 | 
|  |     79 |             rtac imageI, rtac Xa]);
 | 
| 969 |     80 | qed "disj_lemma";
 | 
|  |     81 | 
 | 
| 1888 |     82 | goalw Lfp.thy [image_def]
 | 
|  |     83 |     "range(%z. if z:X then f(z) else g(z)) = f``X Un g``Compl(X)";
 | 
| 4089 |     84 | by (simp_tac (simpset() addsplits [expand_if]) 1);
 | 
| 2935 |     85 | by (Blast_tac 1);
 | 
| 969 |     86 | qed "range_if_then_else";
 | 
|  |     87 | 
 | 
|  |     88 | goal Lfp.thy "a : X Un Compl(X)";
 | 
| 2935 |     89 | by (Blast_tac 1);
 | 
| 969 |     90 | qed "X_Un_Compl";
 | 
|  |     91 | 
 | 
|  |     92 | goalw Lfp.thy [surj_def] "surj(f) = (!a. a : range(f))";
 | 
| 4089 |     93 | by (fast_tac (claset() addEs [ssubst]) 1);
 | 
| 969 |     94 | qed "surj_iff_full_range";
 | 
|  |     95 | 
 | 
|  |     96 | val [compl] = goal Lfp.thy
 | 
|  |     97 |     "Compl(f``X) = g``Compl(X) ==> surj(%z. if z:X then f(z) else g(z))";
 | 
| 1487 |     98 | by (EVERY1[stac surj_iff_full_range, stac range_if_then_else,
 | 
|  |     99 |            stac (compl RS sym)]);
 | 
| 969 |    100 | by (rtac (X_Un_Compl RS allI) 1);
 | 
|  |    101 | qed "surj_if_then_else";
 | 
|  |    102 | 
 | 
|  |    103 | val [injf,injg,compl,bij] = goal Lfp.thy
 | 
|  |    104 |     "[| inj_onto f X;  inj_onto g (Compl X);  Compl(f``X) = g``Compl(X); \
 | 
|  |    105 | \       bij = (%z. if z:X then f(z) else g(z)) |] ==> \
 | 
|  |    106 | \       inj(bij) & surj(bij)";
 | 
|  |    107 | val f_eq_gE = make_elim (compl RS disj_lemma);
 | 
| 2031 |    108 | by (stac bij 1);
 | 
| 969 |    109 | by (rtac conjI 1);
 | 
|  |    110 | by (rtac (compl RS surj_if_then_else) 2);
 | 
|  |    111 | by (rewtac inj_def);
 | 
|  |    112 | by (cut_facts_tac [injf,injg] 1);
 | 
|  |    113 | by (EVERY1 [rtac allI, rtac allI, stac expand_if, rtac conjI, stac expand_if]);
 | 
| 4089 |    114 | by (fast_tac (claset() addEs  [inj_ontoD, sym RS f_eq_gE]) 1);
 | 
| 969 |    115 | by (stac expand_if 1);
 | 
| 4089 |    116 | by (fast_tac (claset() addEs  [inj_ontoD, f_eq_gE]) 1);
 | 
| 969 |    117 | qed "bij_if_then_else";
 | 
|  |    118 | 
 | 
|  |    119 | goal Lfp.thy "? X. X = Compl(g``Compl((f:: 'a=>'b)``X))";
 | 
|  |    120 | by (rtac exI 1);
 | 
|  |    121 | by (rtac lfp_Tarski 1);
 | 
|  |    122 | by (REPEAT (ares_tac [monoI, image_mono, Compl_anti_mono] 1));
 | 
|  |    123 | qed "decomposition";
 | 
|  |    124 | 
 | 
|  |    125 | val [injf,injg] = goal Lfp.thy
 | 
|  |    126 |    "[| inj(f:: 'a=>'b);  inj(g:: 'b=>'a) |] ==> \
 | 
|  |    127 | \   ? h:: 'a=>'b. inj(h) & surj(h)";
 | 
|  |    128 | by (rtac (decomposition RS exE) 1);
 | 
|  |    129 | by (rtac exI 1);
 | 
|  |    130 | by (rtac bij_if_then_else 1);
 | 
|  |    131 | by (EVERY [rtac refl 4, rtac (injf RS inj_imp) 1,
 | 
| 2911 |    132 |            rtac (injg RS inj_onto_inv) 1]);
 | 
| 969 |    133 | by (EVERY1 [etac ssubst, stac double_complement, rtac subsetI,
 | 
| 1465 |    134 |             etac imageE, etac ssubst, rtac rangeI]);
 | 
| 969 |    135 | by (EVERY1 [etac ssubst, stac double_complement, 
 | 
| 1465 |    136 |             rtac (injg RS inv_image_comp RS sym)]);
 | 
| 969 |    137 | qed "schroeder_bernstein";
 | 
|  |    138 | 
 | 
|  |    139 | writeln"Reached end of file.";
 |