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