src/HOL/ex/set.ML
author paulson
Wed, 03 Feb 1999 13:26:07 +0100
changeset 6171 cd237a10cbf8
parent 6146 00f3324048a7
child 6236 958f4fc3e8b8
permissions -rw-r--r--
inj is now a translation of inj_on
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
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4109
diff changeset
    12
context Lfp.thy;
2998
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    13
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    14
(*trivial example of term synthesis: apparently hard for some provers!*)
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    15
Goal "a ~= b ==> a:?X & b ~: ?X";
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    16
by (Blast_tac 1);
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    17
result();
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    18
5724
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    19
(** Examples for the Blast_tac paper **)
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    20
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    21
(*Union-image, called Un_Union_image on equalities.ML*)
6146
00f3324048a7 renamed variables for clarity
paulson
parents: 5786
diff changeset
    22
Goal "(UN x:C. f(x) Un g(x)) = Union(f``C)  Un  Union(g``C)";
5724
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    23
by (Blast_tac 1);
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    24
result();
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    25
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    26
(*Inter-image, called Int_Inter_image on equalities.ML*)
6146
00f3324048a7 renamed variables for clarity
paulson
parents: 5786
diff changeset
    27
Goal "(INT x:C. f(x) Int g(x)) = Inter(f``C) Int Inter(g``C)";
5724
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    28
by (Blast_tac 1);
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    29
result();
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    30
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    31
(*Singleton I.  Nice demonstration of blast_tac--and its limitations*)
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    32
Goal "!!S::'a set set. ALL x:S. ALL y:S. x<=y ==> EX z. S <= {z}";
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4109
diff changeset
    33
(*for some unfathomable reason, UNIV_I increases the search space greatly*)
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4109
diff changeset
    34
by (blast_tac (claset() delrules [UNIV_I]) 1);
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4109
diff changeset
    35
result();
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4109
diff changeset
    36
5724
a9f8cb9b5b5d standard Blast_tac demos
paulson
parents: 5490
diff changeset
    37
(*Singleton II.  variant of the benchmark above*)
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    38
Goal "ALL x:S. Union(S) <= x ==> EX z. S <= {z}";
4324
9bfac4684f2f New example
paulson
parents: 4153
diff changeset
    39
by (blast_tac (claset() delrules [UNIV_I]) 1);
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    40
(*just Blast_tac takes 5 seconds instead of 1*)
4324
9bfac4684f2f New example
paulson
parents: 4153
diff changeset
    41
result();
2998
62a5230883bb New blast_tac demo
paulson
parents: 2935
diff changeset
    42
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    43
(*** A unique fixpoint theorem --- fast/best/meson all fail ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    44
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    45
Goal "?!x. f(g(x))=x ==> ?!y. g(f(y))=y";
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    46
by (EVERY1[etac ex1E, rtac ex1I, etac arg_cong,
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    47
          rtac subst, atac, etac allE, rtac arg_cong, etac mp, etac arg_cong]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    48
result();
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    49
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    50
(*** Cantor's Theorem: There is no surjection from a set to its powerset. ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    51
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    52
goal Set.thy "~ (? f:: 'a=>'a set. ! S. ? x. f(x) = S)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    53
(*requires best-first search because it is undirectional*)
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    54
by (best_tac (claset() addSEs [equalityCE]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    55
qed "cantor1";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    56
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    57
(*This form displays the diagonal term*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    58
goal Set.thy "! f:: 'a=>'a set. ! x. f(x) ~= ?S(f)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    59
by (best_tac (claset() addSEs [equalityCE]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    60
uresult();
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    61
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    62
(*This form exploits the set constructs*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    63
goal Set.thy "?S ~: range(f :: 'a=>'a set)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    64
by (rtac notI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    65
by (etac rangeE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    66
by (etac equalityCE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    67
by (dtac CollectD 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    68
by (contr_tac 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    69
by (swap_res_tac [CollectI] 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    70
by (assume_tac 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    71
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    72
choplev 0;
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    73
by (best_tac (claset() addSEs [equalityCE]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    74
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    75
(*** The Schroder-Berstein Theorem ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    76
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    77
Goalw [image_def] "inj(f) ==> inv(f)``(f``X) = X";
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    78
by (rtac equalityI 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    79
by (fast_tac (claset() addEs [inv_f_f RS ssubst]) 1);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    80
by (fast_tac (claset() addEs [inv_f_f RS ssubst]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    81
qed "inv_image_comp";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    82
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    83
Goal "f(a) ~: (f``X) ==> a~:X";
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2911
diff changeset
    84
by (Blast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    85
qed "contra_imageI";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    86
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5432
diff changeset
    87
Goal "(a ~: -(X)) = (a:X)";
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2911
diff changeset
    88
by (Blast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    89
qed "not_Compl";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    90
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    91
(*Lots of backtracking in this proof...*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    92
val [compl,fg,Xa] = goal Lfp.thy
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5432
diff changeset
    93
    "[| -(f``X) = g``(-X);  f(a)=g(b);  a:X |] ==> b:X";
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    94
by (EVERY1 [rtac (not_Compl RS subst), rtac contra_imageI,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
    95
            rtac (compl RS subst), rtac (fg RS subst), stac not_Compl,
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
    96
            rtac imageI, rtac Xa]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    97
qed "disj_lemma";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    98
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
    99
Goalw [image_def]
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5432
diff changeset
   100
     "range(%z. if z:X then f(z) else g(z)) = f``X Un g``(-X)";
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4324
diff changeset
   101
by (Simp_tac 1);
2935
998cb95fdd43 Yet more fast_tac->blast_tac, and other tidying
paulson
parents: 2911
diff changeset
   102
by (Blast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   103
qed "range_if_then_else";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   104
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
   105
Goalw [surj_def] "surj(f) = (!a. a : range(f))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   106
by (fast_tac (claset() addEs [ssubst]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   107
qed "surj_iff_full_range";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   108
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5432
diff changeset
   109
Goal "-(f``X) = g``(-X) ==> surj(%z. if z:X then f(z) else g(z))";
1487
afc1c1f2523e replace sstac
nipkow
parents: 1465
diff changeset
   110
by (EVERY1[stac surj_iff_full_range, stac range_if_then_else,
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
   111
           etac subst]);
5490
85855f65d0c6 From Compl(A) to -A
paulson
parents: 5432
diff changeset
   112
by (Blast_tac 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   113
qed "surj_if_then_else";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   114
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   115
Goalw [inj_on_def]
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   116
     "[| inj_on f X;  inj_on g (-X);  -(f``X) = g``(-X); \
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   117
\        bij = (%z. if z:X then f(z) else g(z)) |]       \
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   118
\     ==> inj(bij) & surj(bij)";
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   119
by (asm_simp_tac (simpset() addsimps [surj_if_then_else]) 1);
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   120
   (*PROOF FAILED if inj_onD*)
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   121
by (blast_tac (claset() addDs [disj_lemma, sym RSN (2,disj_lemma)]) 1);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   122
qed "bij_if_then_else";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   123
5786
9a2c90bdadfe increased precedence of unary minus from 80 to 100
paulson
parents: 5724
diff changeset
   124
Goal "? X. X = - (g``(- (f``X)))";
969
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 lfp_Tarski 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   127
by (REPEAT (ares_tac [monoI, image_mono, Compl_anti_mono] 1));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   128
qed "decomposition";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   129
5432
983b9bf8e89f new example; tidying
paulson
parents: 4831
diff changeset
   130
val [injf,injg] = goal Lfp.thy 
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   131
   "[| inj (f:: 'a=>'b);  inj (g:: 'b=>'a) |] ==> \
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   132
\   ? h:: 'a=>'b. inj(h) & surj(h)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   133
by (rtac (decomposition RS exE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   134
by (rtac exI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   135
by (rtac bij_if_then_else 1);
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   136
by (rtac refl 4);
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 6146
diff changeset
   137
by (EVERY [rtac ([subset_UNIV,injf] MRS subset_inj_on) 1,
4831
dae4d63a1318 Renamed expand_const -> split_const.
nipkow
parents: 4686
diff changeset
   138
           rtac (injg RS inj_on_inv) 1]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   139
by (EVERY1 [etac ssubst, stac double_complement, rtac subsetI,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
   140
            etac imageE, etac ssubst, rtac rangeI]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   141
by (EVERY1 [etac ssubst, stac double_complement, 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 969
diff changeset
   142
            rtac (injg RS inv_image_comp RS sym)]);
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   143
qed "schroeder_bernstein";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   144
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   145
writeln"Reached end of file.";