clasohm@1465: (* Title: HOL/ex/set.ML clasohm@969: ID: $Id$ clasohm@1465: Author: Tobias Nipkow, Cambridge University Computer Laboratory clasohm@969: Copyright 1991 University of Cambridge clasohm@969: clasohm@969: Cantor's Theorem; the Schroeder-Berstein Theorem. clasohm@969: *) clasohm@969: clasohm@969: clasohm@969: writeln"File HOL/ex/set."; clasohm@969: paulson@4153: context Lfp.thy; paulson@2998: paulson@4153: (*Nice demonstration of blast_tac--and its limitations*) paulson@2998: goal Set.thy "!!S::'a set set. ALL x:S. ALL y:S. x<=y ==> EX z. S <= {z}"; paulson@4153: (*for some unfathomable reason, UNIV_I increases the search space greatly*) paulson@4153: by (blast_tac (claset() delrules [UNIV_I]) 1); paulson@4153: result(); paulson@4153: paulson@2998: clasohm@969: (*** A unique fixpoint theorem --- fast/best/meson all fail ***) clasohm@969: wenzelm@3842: val [prem] = goal HOL.thy "?!x. f(g(x))=x ==> ?!y. g(f(y))=y"; paulson@2031: by (EVERY1[rtac (prem RS ex1E), rtac ex1I, etac arg_cong, clasohm@969: rtac subst, atac, etac allE, rtac arg_cong, etac mp, etac arg_cong]); clasohm@969: result(); clasohm@969: clasohm@969: (*** Cantor's Theorem: There is no surjection from a set to its powerset. ***) clasohm@969: clasohm@969: goal Set.thy "~ (? f:: 'a=>'a set. ! S. ? x. f(x) = S)"; clasohm@969: (*requires best-first search because it is undirectional*) wenzelm@4089: by (best_tac (claset() addSEs [equalityCE]) 1); clasohm@969: qed "cantor1"; clasohm@969: clasohm@969: (*This form displays the diagonal term*) clasohm@969: goal Set.thy "! f:: 'a=>'a set. ! x. f(x) ~= ?S(f)"; wenzelm@4089: by (best_tac (claset() addSEs [equalityCE]) 1); clasohm@969: uresult(); clasohm@969: clasohm@969: (*This form exploits the set constructs*) clasohm@969: goal Set.thy "?S ~: range(f :: 'a=>'a set)"; clasohm@969: by (rtac notI 1); clasohm@969: by (etac rangeE 1); clasohm@969: by (etac equalityCE 1); clasohm@969: by (dtac CollectD 1); clasohm@969: by (contr_tac 1); clasohm@969: by (swap_res_tac [CollectI] 1); clasohm@969: by (assume_tac 1); clasohm@969: clasohm@969: choplev 0; wenzelm@4089: by (best_tac (claset() addSEs [equalityCE]) 1); clasohm@969: clasohm@969: (*** The Schroder-Berstein Theorem ***) clasohm@969: paulson@2935: goalw Lfp.thy [image_def] "!!f. inj(f) ==> inv(f)``(f``X) = X"; clasohm@969: by (rtac equalityI 1); wenzelm@4089: by (fast_tac (claset() addEs [inv_f_f RS ssubst]) 1); wenzelm@4089: by (fast_tac (claset() addEs [inv_f_f RS ssubst]) 1); clasohm@969: qed "inv_image_comp"; clasohm@969: paulson@1888: goal Set.thy "!!f. f(a) ~: (f``X) ==> a~:X"; paulson@2935: by (Blast_tac 1); clasohm@969: qed "contra_imageI"; clasohm@969: clasohm@969: goal Lfp.thy "(a ~: Compl(X)) = (a:X)"; paulson@2935: by (Blast_tac 1); clasohm@969: qed "not_Compl"; clasohm@969: clasohm@969: (*Lots of backtracking in this proof...*) clasohm@969: val [compl,fg,Xa] = goal Lfp.thy clasohm@969: "[| Compl(f``X) = g``Compl(X); f(a)=g(b); a:X |] ==> b:X"; clasohm@969: by (EVERY1 [rtac (not_Compl RS subst), rtac contra_imageI, clasohm@1465: rtac (compl RS subst), rtac (fg RS subst), stac not_Compl, clasohm@1465: rtac imageI, rtac Xa]); clasohm@969: qed "disj_lemma"; clasohm@969: paulson@1888: goalw Lfp.thy [image_def] paulson@1888: "range(%z. if z:X then f(z) else g(z)) = f``X Un g``Compl(X)"; wenzelm@4089: by (simp_tac (simpset() addsplits [expand_if]) 1); paulson@2935: by (Blast_tac 1); clasohm@969: qed "range_if_then_else"; clasohm@969: clasohm@969: goal Lfp.thy "a : X Un Compl(X)"; paulson@2935: by (Blast_tac 1); clasohm@969: qed "X_Un_Compl"; clasohm@969: clasohm@969: goalw Lfp.thy [surj_def] "surj(f) = (!a. a : range(f))"; wenzelm@4089: by (fast_tac (claset() addEs [ssubst]) 1); clasohm@969: qed "surj_iff_full_range"; clasohm@969: clasohm@969: val [compl] = goal Lfp.thy clasohm@969: "Compl(f``X) = g``Compl(X) ==> surj(%z. if z:X then f(z) else g(z))"; nipkow@1487: by (EVERY1[stac surj_iff_full_range, stac range_if_then_else, nipkow@1487: stac (compl RS sym)]); clasohm@969: by (rtac (X_Un_Compl RS allI) 1); clasohm@969: qed "surj_if_then_else"; clasohm@969: clasohm@969: val [injf,injg,compl,bij] = goal Lfp.thy clasohm@969: "[| inj_onto f X; inj_onto g (Compl X); Compl(f``X) = g``Compl(X); \ clasohm@969: \ bij = (%z. if z:X then f(z) else g(z)) |] ==> \ clasohm@969: \ inj(bij) & surj(bij)"; clasohm@969: val f_eq_gE = make_elim (compl RS disj_lemma); paulson@2031: by (stac bij 1); clasohm@969: by (rtac conjI 1); clasohm@969: by (rtac (compl RS surj_if_then_else) 2); clasohm@969: by (rewtac inj_def); clasohm@969: by (cut_facts_tac [injf,injg] 1); clasohm@969: by (EVERY1 [rtac allI, rtac allI, stac expand_if, rtac conjI, stac expand_if]); wenzelm@4089: by (fast_tac (claset() addEs [inj_ontoD, sym RS f_eq_gE]) 1); clasohm@969: by (stac expand_if 1); wenzelm@4089: by (fast_tac (claset() addEs [inj_ontoD, f_eq_gE]) 1); clasohm@969: qed "bij_if_then_else"; clasohm@969: clasohm@969: goal Lfp.thy "? X. X = Compl(g``Compl((f:: 'a=>'b)``X))"; clasohm@969: by (rtac exI 1); clasohm@969: by (rtac lfp_Tarski 1); clasohm@969: by (REPEAT (ares_tac [monoI, image_mono, Compl_anti_mono] 1)); clasohm@969: qed "decomposition"; clasohm@969: clasohm@969: val [injf,injg] = goal Lfp.thy clasohm@969: "[| inj(f:: 'a=>'b); inj(g:: 'b=>'a) |] ==> \ clasohm@969: \ ? h:: 'a=>'b. inj(h) & surj(h)"; clasohm@969: by (rtac (decomposition RS exE) 1); clasohm@969: by (rtac exI 1); clasohm@969: by (rtac bij_if_then_else 1); clasohm@969: by (EVERY [rtac refl 4, rtac (injf RS inj_imp) 1, nipkow@2911: rtac (injg RS inj_onto_inv) 1]); clasohm@969: by (EVERY1 [etac ssubst, stac double_complement, rtac subsetI, clasohm@1465: etac imageE, etac ssubst, rtac rangeI]); clasohm@969: by (EVERY1 [etac ssubst, stac double_complement, clasohm@1465: rtac (injg RS inv_image_comp RS sym)]); clasohm@969: qed "schroeder_bernstein"; clasohm@969: clasohm@969: writeln"Reached end of file.";