src/HOL/ex/set.ML
author paulson
Thu, 22 May 1997 15:11:23 +0200
changeset 3300 4f5ffefa7799
parent 2998 62a5230883bb
child 3842 b55686a7b22c
permissions -rw-r--r--
New example of recdef and permutative rewriting
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
     1
(*  Title:      HOL/ex/set.ML
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
     3
    Author:     Tobias Nipkow, Cambridge University Computer Laboratory
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     5
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     6
Cantor's Theorem; the Schroeder-Berstein Theorem.  
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     7
*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     8
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     9
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    10
writeln"File HOL/ex/set.";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    11
2998
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    12
set_current_thy"Set";
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    13
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    14
(*Nice demonstration of blast_tac--and its overloading problems*)
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    15
goal Set.thy "!!S::'a set set. ALL x:S. ALL y:S. x<=y ==> EX z. S <= {z}";
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    16
let val insertCI' = read_instantiate [("'a", "?'a set")] insertCI
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    17
in    (*Type instantiation is required so that blast_tac can apply equalityI
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    18
        to the subgoal arising from insertCI*)
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    19
by(blast_tac (!claset addSIs [insertCI']) 1)
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    20
end;
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    21
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    22
(*** A unique fixpoint theorem --- fast/best/meson all fail ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    23
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    24
val [prem] = goal HOL.thy "?!x.f(g(x))=x ==> ?!y.g(f(y))=y";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1888
diff changeset
    25
by (EVERY1[rtac (prem RS ex1E), rtac ex1I, etac arg_cong,
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    26
          rtac subst, atac, etac allE, rtac arg_cong, etac mp, etac arg_cong]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    27
result();
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    28
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    29
(*** Cantor's Theorem: There is no surjection from a set to its powerset. ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    30
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    31
goal Set.thy "~ (? f:: 'a=>'a set. ! S. ? x. f(x) = S)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    32
(*requires best-first search because it is undirectional*)
1820
e381e1c51689 Classical tactics now use default claset.
berghofe
parents: 1487
diff changeset
    33
by (best_tac (!claset addSEs [equalityCE]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    34
qed "cantor1";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    35
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    36
(*This form displays the diagonal term*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    37
goal Set.thy "! f:: 'a=>'a set. ! x. f(x) ~= ?S(f)";
1820
e381e1c51689 Classical tactics now use default claset.
berghofe
parents: 1487
diff changeset
    38
by (best_tac (!claset addSEs [equalityCE]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    39
uresult();
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    40
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    41
(*This form exploits the set constructs*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    42
goal Set.thy "?S ~: range(f :: 'a=>'a set)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    43
by (rtac notI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    44
by (etac rangeE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    45
by (etac equalityCE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    46
by (dtac CollectD 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    47
by (contr_tac 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    48
by (swap_res_tac [CollectI] 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    49
by (assume_tac 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    50
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    51
choplev 0;
1820
e381e1c51689 Classical tactics now use default claset.
berghofe
parents: 1487
diff changeset
    52
by (best_tac (!claset addSEs [equalityCE]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    53
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    54
(*** The Schroder-Berstein Theorem ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    55
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2911
diff changeset
    56
goalw Lfp.thy [image_def] "!!f. inj(f) ==> inv(f)``(f``X) = X";
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    57
by (rtac equalityI 1);
2911
8a680e310f04 Inv -> inv
nipkow
parents: 2031
diff changeset
    58
by (fast_tac (!claset addEs [inv_f_f RS ssubst]) 1);
8a680e310f04 Inv -> inv
nipkow
parents: 2031
diff changeset
    59
by (fast_tac (!claset addEs [inv_f_f RS ssubst]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    60
qed "inv_image_comp";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    61
1888
acb7363994cb Removal of cfast_tac
paulson
parents: 1820
diff changeset
    62
goal Set.thy "!!f. f(a) ~: (f``X) ==> a~:X";
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2911
diff changeset
    63
by (Blast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    64
qed "contra_imageI";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    65
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    66
goal Lfp.thy "(a ~: Compl(X)) = (a:X)";
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2911
diff changeset
    67
by (Blast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    68
qed "not_Compl";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    69
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    70
(*Lots of backtracking in this proof...*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    71
val [compl,fg,Xa] = goal Lfp.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    72
    "[| Compl(f``X) = g``Compl(X);  f(a)=g(b);  a:X |] ==> b:X";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    73
by (EVERY1 [rtac (not_Compl RS subst), rtac contra_imageI,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
    74
            rtac (compl RS subst), rtac (fg RS subst), stac not_Compl,
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
    75
            rtac imageI, rtac Xa]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    76
qed "disj_lemma";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    77
1888
acb7363994cb Removal of cfast_tac
paulson
parents: 1820
diff changeset
    78
goalw Lfp.thy [image_def]
acb7363994cb Removal of cfast_tac
paulson
parents: 1820
diff changeset
    79
    "range(%z. if z:X then f(z) else g(z)) = f``X Un g``Compl(X)";
acb7363994cb Removal of cfast_tac
paulson
parents: 1820
diff changeset
    80
by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2911
diff changeset
    81
by (Blast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    82
qed "range_if_then_else";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    83
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    84
goal Lfp.thy "a : X Un Compl(X)";
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2911
diff changeset
    85
by (Blast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    86
qed "X_Un_Compl";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    87
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    88
goalw Lfp.thy [surj_def] "surj(f) = (!a. a : range(f))";
1820
e381e1c51689 Classical tactics now use default claset.
berghofe
parents: 1487
diff changeset
    89
by (fast_tac (!claset addEs [ssubst]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    90
qed "surj_iff_full_range";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    91
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    92
val [compl] = goal Lfp.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    93
    "Compl(f``X) = g``Compl(X) ==> surj(%z. if z:X then f(z) else g(z))";
1487
afc1c1f2523e replace sstac
nipkow
parents: 1465
diff changeset
    94
by (EVERY1[stac surj_iff_full_range, stac range_if_then_else,
afc1c1f2523e replace sstac
nipkow
parents: 1465
diff changeset
    95
           stac (compl RS sym)]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    96
by (rtac (X_Un_Compl RS allI) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    97
qed "surj_if_then_else";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    98
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    99
val [injf,injg,compl,bij] = goal Lfp.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   100
    "[| inj_onto f X;  inj_onto g (Compl X);  Compl(f``X) = g``Compl(X); \
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   101
\       bij = (%z. if z:X then f(z) else g(z)) |] ==> \
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   102
\       inj(bij) & surj(bij)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   103
val f_eq_gE = make_elim (compl RS disj_lemma);
2031
03a843f0f447 Ran expandshort
paulson
parents: 1888
diff changeset
   104
by (stac bij 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   105
by (rtac conjI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   106
by (rtac (compl RS surj_if_then_else) 2);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   107
by (rewtac inj_def);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   108
by (cut_facts_tac [injf,injg] 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   109
by (EVERY1 [rtac allI, rtac allI, stac expand_if, rtac conjI, stac expand_if]);
1820
e381e1c51689 Classical tactics now use default claset.
berghofe
parents: 1487
diff changeset
   110
by (fast_tac (!claset addEs  [inj_ontoD, sym RS f_eq_gE]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   111
by (stac expand_if 1);
1820
e381e1c51689 Classical tactics now use default claset.
berghofe
parents: 1487
diff changeset
   112
by (fast_tac (!claset addEs  [inj_ontoD, f_eq_gE]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   113
qed "bij_if_then_else";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   114
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   115
goal Lfp.thy "? X. X = Compl(g``Compl((f:: 'a=>'b)``X))";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   116
by (rtac exI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   117
by (rtac lfp_Tarski 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   118
by (REPEAT (ares_tac [monoI, image_mono, Compl_anti_mono] 1));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   119
qed "decomposition";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   120
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   121
val [injf,injg] = goal Lfp.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   122
   "[| inj(f:: 'a=>'b);  inj(g:: 'b=>'a) |] ==> \
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   123
\   ? h:: 'a=>'b. inj(h) & surj(h)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   124
by (rtac (decomposition RS exE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   125
by (rtac exI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   126
by (rtac bij_if_then_else 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   127
by (EVERY [rtac refl 4, rtac (injf RS inj_imp) 1,
2911
8a680e310f04 Inv -> inv
nipkow
parents: 2031
diff changeset
   128
           rtac (injg RS inj_onto_inv) 1]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   129
by (EVERY1 [etac ssubst, stac double_complement, rtac subsetI,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
   130
            etac imageE, etac ssubst, rtac rangeI]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   131
by (EVERY1 [etac ssubst, stac double_complement, 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
   132
            rtac (injg RS inv_image_comp RS sym)]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   133
qed "schroeder_bernstein";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   134
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   135
writeln"Reached end of file.";