src/HOL/ex/set.thy
 changeset 44276 fe769a0fcc96 parent 44263 971d1be5d5ce child 44277 bcb696533579
     1.1 --- a/src/HOL/ex/set.thy	Thu Aug 18 16:52:19 2011 +0900
1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,225 +0,0 @@
1.4 -(*  Title:      HOL/ex/set.thy
1.5 -    Author:     Tobias Nipkow and Lawrence C Paulson
1.6 -    Copyright   1991  University of Cambridge
1.7 -*)
1.8 -
1.9 -header {* Set Theory examples: Cantor's Theorem, Schröder-Bernstein Theorem, etc. *}
1.10 -
1.11 -theory set imports Main begin
1.12 -
1.13 -text{*
1.14 -  These two are cited in Benzmueller and Kohlhase's system description
1.15 -  of LEO, CADE-15, 1998 (pages 139-143) as theorems LEO could not
1.16 -  prove.
1.17 -*}
1.18 -
1.19 -lemma "(X = Y \<union> Z) =
1.20 -    (Y \<subseteq> X \<and> Z \<subseteq> X \<and> (\<forall>V. Y \<subseteq> V \<and> Z \<subseteq> V \<longrightarrow> X \<subseteq> V))"
1.21 -  by blast
1.22 -
1.23 -lemma "(X = Y \<inter> Z) =
1.24 -    (X \<subseteq> Y \<and> X \<subseteq> Z \<and> (\<forall>V. V \<subseteq> Y \<and> V \<subseteq> Z \<longrightarrow> V \<subseteq> X))"
1.25 -  by blast
1.26 -
1.27 -text {*
1.28 -  Trivial example of term synthesis: apparently hard for some provers!
1.29 -*}
1.30 -
1.31 -schematic_lemma "a \<noteq> b \<Longrightarrow> a \<in> ?X \<and> b \<notin> ?X"
1.32 -  by blast
1.33 -
1.34 -
1.35 -subsection {* Examples for the @{text blast} paper *}
1.36 -
1.37 -lemma "(\<Union>x \<in> C. f x \<union> g x) = \<Union>(f  C)  \<union>  \<Union>(g  C)"
1.38 -  -- {* Union-image, called @{text Un_Union_image} in Main HOL *}
1.39 -  by blast
1.40 -
1.41 -lemma "(\<Inter>x \<in> C. f x \<inter> g x) = \<Inter>(f  C) \<inter> \<Inter>(g  C)"
1.42 -  -- {* Inter-image, called @{text Int_Inter_image} in Main HOL *}
1.43 -  by blast
1.44 -
1.45 -lemma singleton_example_1:
1.46 -     "\<And>S::'a set set. \<forall>x \<in> S. \<forall>y \<in> S. x \<subseteq> y \<Longrightarrow> \<exists>z. S \<subseteq> {z}"
1.47 -  by blast
1.48 -
1.49 -lemma singleton_example_2:
1.50 -     "\<forall>x \<in> S. \<Union>S \<subseteq> x \<Longrightarrow> \<exists>z. S \<subseteq> {z}"
1.51 -  -- {*Variant of the problem above. *}
1.52 -  by blast
1.53 -
1.54 -lemma "\<exists>!x. f (g x) = x \<Longrightarrow> \<exists>!y. g (f y) = y"
1.55 -  -- {* A unique fixpoint theorem --- @{text fast}/@{text best}/@{text meson} all fail. *}
1.56 -  by metis
1.57 -
1.58 -
1.59 -subsection {* Cantor's Theorem: There is no surjection from a set to its powerset *}
1.60 -
1.61 -lemma cantor1: "\<not> (\<exists>f:: 'a \<Rightarrow> 'a set. \<forall>S. \<exists>x. f x = S)"
1.62 -  -- {* Requires best-first search because it is undirectional. *}
1.63 -  by best
1.64 -
1.65 -schematic_lemma "\<forall>f:: 'a \<Rightarrow> 'a set. \<forall>x. f x \<noteq> ?S f"
1.66 -  -- {*This form displays the diagonal term. *}
1.67 -  by best
1.68 -
1.69 -schematic_lemma "?S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
1.70 -  -- {* This form exploits the set constructs. *}
1.71 -  by (rule notI, erule rangeE, best)
1.72 -
1.73 -schematic_lemma "?S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
1.74 -  -- {* Or just this! *}
1.75 -  by best
1.76 -
1.77 -
1.78 -subsection {* The Schröder-Berstein Theorem *}
1.79 -
1.80 -lemma disj_lemma: "- (f  X) = g  (-X) \<Longrightarrow> f a = g b \<Longrightarrow> a \<in> X \<Longrightarrow> b \<in> X"
1.81 -  by blast
1.82 -
1.83 -lemma surj_if_then_else:
1.84 -  "-(f  X) = g  (-X) \<Longrightarrow> surj (\<lambda>z. if z \<in> X then f z else g z)"
1.85 -  by (simp add: surj_def) blast
1.86 -
1.87 -lemma bij_if_then_else:
1.88 -  "inj_on f X \<Longrightarrow> inj_on g (-X) \<Longrightarrow> -(f  X) = g  (-X) \<Longrightarrow>
1.89 -    h = (\<lambda>z. if z \<in> X then f z else g z) \<Longrightarrow> inj h \<and> surj h"
1.90 -  apply (unfold inj_on_def)
1.91 -  apply (simp add: surj_if_then_else)
1.92 -  apply (blast dest: disj_lemma sym)
1.93 -  done
1.94 -
1.95 -lemma decomposition: "\<exists>X. X = - (g  (- (f  X)))"
1.96 -  apply (rule exI)
1.97 -  apply (rule lfp_unfold)
1.98 -  apply (rule monoI, blast)
1.99 -  done
1.100 -
1.101 -theorem Schroeder_Bernstein:
1.102 -  "inj (f :: 'a \<Rightarrow> 'b) \<Longrightarrow> inj (g :: 'b \<Rightarrow> 'a)
1.103 -    \<Longrightarrow> \<exists>h:: 'a \<Rightarrow> 'b. inj h \<and> surj h"
1.104 -  apply (rule decomposition [where f=f and g=g, THEN exE])
1.105 -  apply (rule_tac x = "(\<lambda>z. if z \<in> x then f z else inv g z)" in exI)
1.106 -    --{*The term above can be synthesized by a sufficiently detailed proof.*}
1.107 -  apply (rule bij_if_then_else)
1.108 -     apply (rule_tac  refl)
1.109 -    apply (rule_tac  inj_on_inv_into)
1.110 -    apply (erule subset_inj_on [OF _ subset_UNIV])
1.111 -   apply blast
1.112 -  apply (erule ssubst, subst double_complement, erule inv_image_comp [symmetric])
1.113 -  done
1.114 -
1.115 -
1.116 -subsection {* A simple party theorem *}
1.117 -
1.118 -text{* \emph{At any party there are two people who know the same
1.119 -number of people}. Provided the party consists of at least two people
1.120 -and the knows relation is symmetric. Knowing yourself does not count
1.121 ---- otherwise knows needs to be reflexive. (From Freek Wiedijk's talk
1.122 -at TPHOLs 2007.) *}
1.123 -
1.124 -lemma equal_number_of_acquaintances:
1.125 -assumes "Domain R <= A" and "sym R" and "card A \<ge> 2"
1.126 -shows "\<not> inj_on (%a. card(R  {a} - {a})) A"
1.127 -proof -
1.128 -  let ?N = "%a. card(R  {a} - {a})"
1.129 -  let ?n = "card A"
1.130 -  have "finite A" using card A \<ge> 2 by(auto intro:ccontr)
1.131 -  have 0: "R  A <= A" using sym R Domain R <= A
1.132 -    unfolding Domain_def sym_def by blast
1.133 -  have h: "ALL a:A. R  {a} <= A" using 0 by blast
1.134 -  hence 1: "ALL a:A. finite(R  {a})" using finite A
1.135 -    by(blast intro: finite_subset)
1.136 -  have sub: "?N  A <= {0..<?n}"
1.137 -  proof -
1.138 -    have "ALL a:A. R  {a} - {a} < A" using h by blast
1.139 -    thus ?thesis using psubset_card_mono[OF finite A] by auto
1.140 -  qed
1.141 -  show "~ inj_on ?N A" (is "~ ?I")
1.142 -  proof
1.143 -    assume ?I
1.144 -    hence "?n = card(?N  A)" by(rule card_image[symmetric])
1.145 -    with sub finite A have 2[simp]: "?N  A = {0..<?n}"
1.146 -      using subset_card_intvl_is_intvl[of _ 0] by(auto)
1.147 -    have "0 : ?N  A" and "?n - 1 : ?N  A"  using card A \<ge> 2 by simp+
1.148 -    then obtain a b where ab: "a:A" "b:A" and Na: "?N a = 0" and Nb: "?N b = ?n - 1"
1.149 -      by (auto simp del: 2)
1.150 -    have "a \<noteq> b" using Na Nb card A \<ge> 2 by auto
1.151 -    have "R  {a} - {a} = {}" by (metis 1 Na ab card_eq_0_iff finite_Diff)
1.152 -    hence "b \<notin> R  {a}" using a\<noteq>b by blast
1.153 -    hence "a \<notin> R  {b}" by (metis Image_singleton_iff assms(2) sym_def)
1.154 -    hence 3: "R  {b} - {b} <= A - {a,b}" using 0 ab by blast
1.155 -    have 4: "finite (A - {a,b})" using finite A by simp
1.156 -    have "?N b <= ?n - 2" using ab a\<noteq>b finite A card_mono[OF 4 3] by simp
1.157 -    then show False using Nb card A \<ge>  2 by arith
1.158 -  qed
1.159 -qed
1.160 -
1.161 -text {*
1.162 -  From W. W. Bledsoe and Guohui Feng, SET-VAR. JAR 11 (3), 1993, pages
1.163 -  293-314.
1.164 -
1.165 -  Isabelle can prove the easy examples without any special mechanisms,
1.166 -  but it can't prove the hard ones.
1.167 -*}
1.168 -
1.169 -lemma "\<exists>A. (\<forall>x \<in> A. x \<le> (0::int))"
1.170 -  -- {* Example 1, page 295. *}
1.171 -  by force
1.172 -
1.173 -lemma "D \<in> F \<Longrightarrow> \<exists>G. \<forall>A \<in> G. \<exists>B \<in> F. A \<subseteq> B"
1.174 -  -- {* Example 2. *}
1.175 -  by force
1.176 -
1.177 -lemma "P a \<Longrightarrow> \<exists>A. (\<forall>x \<in> A. P x) \<and> (\<exists>y. y \<in> A)"
1.178 -  -- {* Example 3. *}
1.179 -  by force
1.180 -
1.181 -lemma "a < b \<and> b < (c::int) \<Longrightarrow> \<exists>A. a \<notin> A \<and> b \<in> A \<and> c \<notin> A"
1.182 -  -- {* Example 4. *}
1.183 -  by force
1.184 -
1.185 -lemma "P (f b) \<Longrightarrow> \<exists>s A. (\<forall>x \<in> A. P x) \<and> f s \<in> A"
1.186 -  -- {*Example 5, page 298. *}
1.187 -  by force
1.188 -
1.189 -lemma "P (f b) \<Longrightarrow> \<exists>s A. (\<forall>x \<in> A. P x) \<and> f s \<in> A"
1.190 -  -- {* Example 6. *}
1.191 -  by force
1.192 -
1.193 -lemma "\<exists>A. a \<notin> A"
1.194 -  -- {* Example 7. *}
1.195 -  by force
1.196 -
1.197 -lemma "(\<forall>u v. u < (0::int) \<longrightarrow> u \<noteq> abs v)
1.198 -    \<longrightarrow> (\<exists>A::int set. (\<forall>y. abs y \<notin> A) \<and> -2 \<in> A)"
1.199 -  -- {* Example 8 now needs a small hint. *}
1.200 -  by (simp add: abs_if, force)
1.201 -    -- {* not @{text blast}, which can't simplify @{text "-2 < 0"} *}
1.202 -
1.203 -text {* Example 9 omitted (requires the reals). *}
1.204 -
1.205 -text {* The paper has no Example 10! *}
1.206 -
1.207 -lemma "(\<forall>A. 0 \<in> A \<and> (\<forall>x \<in> A. Suc x \<in> A) \<longrightarrow> n \<in> A) \<and>
1.208 -  P 0 \<and> (\<forall>x. P x \<longrightarrow> P (Suc x)) \<longrightarrow> P n"
1.209 -  -- {* Example 11: needs a hint. *}
1.210 -by(metis nat.induct)
1.211 -
1.212 -lemma
1.213 -  "(\<forall>A. (0, 0) \<in> A \<and> (\<forall>x y. (x, y) \<in> A \<longrightarrow> (Suc x, Suc y) \<in> A) \<longrightarrow> (n, m) \<in> A)
1.214 -    \<and> P n \<longrightarrow> P m"
1.215 -  -- {* Example 12. *}
1.216 -  by auto
1.217 -
1.218 -lemma
1.219 -  "(\<forall>x. (\<exists>u. x = 2 * u) = (\<not> (\<exists>v. Suc x = 2 * v))) \<longrightarrow>
1.220 -    (\<exists>A. \<forall>x. (x \<in> A) = (Suc x \<notin> A))"
1.221 -  -- {* Example EO1: typo in article, and with the obvious fix it seems
1.222 -      to require arithmetic reasoning. *}
1.223 -  apply clarify
1.224 -  apply (rule_tac x = "{x. \<exists>u. x = 2 * u}" in exI, auto)
1.225 -   apply metis+
1.226 -  done
1.227 -
1.228 -end
`