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