src/HOL/ex/set.thy
 author bulwahn Fri Jan 07 14:46:28 2011 +0100 (2011-01-07) changeset 41460 ea56b98aee83 parent 40945 b8703f63bfb2 permissions -rw-r--r--
removing obselete Id comments from HOL/ex theories
     1 (*  Title:      HOL/ex/set.thy

     2     Author:     Tobias Nipkow and Lawrence C Paulson

     3     Copyright   1991  University of Cambridge

     4 *)

     5

     6 header {* Set Theory examples: Cantor's Theorem, Schröder-Bernstein Theorem, etc. *}

     7

     8 theory set imports Main begin

     9

    10 text{*

    11   These two are cited in Benzmueller and Kohlhase's system description

    12   of LEO, CADE-15, 1998 (pages 139-143) as theorems LEO could not

    13   prove.

    14 *}

    15

    16 lemma "(X = Y \<union> Z) =

    17     (Y \<subseteq> X \<and> Z \<subseteq> X \<and> (\<forall>V. Y \<subseteq> V \<and> Z \<subseteq> V \<longrightarrow> X \<subseteq> V))"

    18   by blast

    19

    20 lemma "(X = Y \<inter> Z) =

    21     (X \<subseteq> Y \<and> X \<subseteq> Z \<and> (\<forall>V. V \<subseteq> Y \<and> V \<subseteq> Z \<longrightarrow> V \<subseteq> X))"

    22   by blast

    23

    24 text {*

    25   Trivial example of term synthesis: apparently hard for some provers!

    26 *}

    27

    28 schematic_lemma "a \<noteq> b \<Longrightarrow> a \<in> ?X \<and> b \<notin> ?X"

    29   by blast

    30

    31

    32 subsection {* Examples for the @{text blast} paper *}

    33

    34 lemma "(\<Union>x \<in> C. f x \<union> g x) = \<Union>(f  C)  \<union>  \<Union>(g  C)"

    35   -- {* Union-image, called @{text Un_Union_image} in Main HOL *}

    36   by blast

    37

    38 lemma "(\<Inter>x \<in> C. f x \<inter> g x) = \<Inter>(f  C) \<inter> \<Inter>(g  C)"

    39   -- {* Inter-image, called @{text Int_Inter_image} in Main HOL *}

    40   by blast

    41

    42 lemma singleton_example_1:

    43      "\<And>S::'a set set. \<forall>x \<in> S. \<forall>y \<in> S. x \<subseteq> y \<Longrightarrow> \<exists>z. S \<subseteq> {z}"

    44   by blast

    45

    46 lemma singleton_example_2:

    47      "\<forall>x \<in> S. \<Union>S \<subseteq> x \<Longrightarrow> \<exists>z. S \<subseteq> {z}"

    48   -- {*Variant of the problem above. *}

    49   by blast

    50

    51 lemma "\<exists>!x. f (g x) = x \<Longrightarrow> \<exists>!y. g (f y) = y"

    52   -- {* A unique fixpoint theorem --- @{text fast}/@{text best}/@{text meson} all fail. *}

    53   by metis

    54

    55

    56 subsection {* Cantor's Theorem: There is no surjection from a set to its powerset *}

    57

    58 lemma cantor1: "\<not> (\<exists>f:: 'a \<Rightarrow> 'a set. \<forall>S. \<exists>x. f x = S)"

    59   -- {* Requires best-first search because it is undirectional. *}

    60   by best

    61

    62 schematic_lemma "\<forall>f:: 'a \<Rightarrow> 'a set. \<forall>x. f x \<noteq> ?S f"

    63   -- {*This form displays the diagonal term. *}

    64   by best

    65

    66 schematic_lemma "?S \<notin> range (f :: 'a \<Rightarrow> 'a set)"

    67   -- {* This form exploits the set constructs. *}

    68   by (rule notI, erule rangeE, best)

    69

    70 schematic_lemma "?S \<notin> range (f :: 'a \<Rightarrow> 'a set)"

    71   -- {* Or just this! *}

    72   by best

    73

    74

    75 subsection {* The Schröder-Berstein Theorem *}

    76

    77 lemma disj_lemma: "- (f  X) = g  (-X) \<Longrightarrow> f a = g b \<Longrightarrow> a \<in> X \<Longrightarrow> b \<in> X"

    78   by blast

    79

    80 lemma surj_if_then_else:

    81   "-(f  X) = g  (-X) \<Longrightarrow> surj (\<lambda>z. if z \<in> X then f z else g z)"

    82   by (simp add: surj_def) blast

    83

    84 lemma bij_if_then_else:

    85   "inj_on f X \<Longrightarrow> inj_on g (-X) \<Longrightarrow> -(f  X) = g  (-X) \<Longrightarrow>

    86     h = (\<lambda>z. if z \<in> X then f z else g z) \<Longrightarrow> inj h \<and> surj h"

    87   apply (unfold inj_on_def)

    88   apply (simp add: surj_if_then_else)

    89   apply (blast dest: disj_lemma sym)

    90   done

    91

    92 lemma decomposition: "\<exists>X. X = - (g  (- (f  X)))"

    93   apply (rule exI)

    94   apply (rule lfp_unfold)

    95   apply (rule monoI, blast)

    96   done

    97

    98 theorem Schroeder_Bernstein:

    99   "inj (f :: 'a \<Rightarrow> 'b) \<Longrightarrow> inj (g :: 'b \<Rightarrow> 'a)

   100     \<Longrightarrow> \<exists>h:: 'a \<Rightarrow> 'b. inj h \<and> surj h"

   101   apply (rule decomposition [where f=f and g=g, THEN exE])

   102   apply (rule_tac x = "(\<lambda>z. if z \<in> x then f z else inv g z)" in exI)

   103     --{*The term above can be synthesized by a sufficiently detailed proof.*}

   104   apply (rule bij_if_then_else)

   105      apply (rule_tac  refl)

   106     apply (rule_tac  inj_on_inv_into)

   107     apply (erule subset_inj_on [OF _ subset_UNIV])

   108    apply blast

   109   apply (erule ssubst, subst double_complement, erule inv_image_comp [symmetric])

   110   done

   111

   112

   113 subsection {* A simple party theorem *}

   114

   115 text{* \emph{At any party there are two people who know the same

   116 number of people}. Provided the party consists of at least two people

   117 and the knows relation is symmetric. Knowing yourself does not count

   118 --- otherwise knows needs to be reflexive. (From Freek Wiedijk's talk

   119 at TPHOLs 2007.) *}

   120

   121 lemma equal_number_of_acquaintances:

   122 assumes "Domain R <= A" and "sym R" and "card A \<ge> 2"

   123 shows "\<not> inj_on (%a. card(R  {a} - {a})) A"

   124 proof -

   125   let ?N = "%a. card(R  {a} - {a})"

   126   let ?n = "card A"

   127   have "finite A" using card A \<ge> 2 by(auto intro:ccontr)

   128   have 0: "R  A <= A" using sym R Domain R <= A

   129     unfolding Domain_def sym_def by blast

   130   have h: "ALL a:A. R  {a} <= A" using 0 by blast

   131   hence 1: "ALL a:A. finite(R  {a})" using finite A

   132     by(blast intro: finite_subset)

   133   have sub: "?N  A <= {0..<?n}"

   134   proof -

   135     have "ALL a:A. R  {a} - {a} < A" using h by blast

   136     thus ?thesis using psubset_card_mono[OF finite A] by auto

   137   qed

   138   show "~ inj_on ?N A" (is "~ ?I")

   139   proof

   140     assume ?I

   141     hence "?n = card(?N  A)" by(rule card_image[symmetric])

   142     with sub finite A have 2[simp]: "?N  A = {0..<?n}"

   143       using subset_card_intvl_is_intvl[of _ 0] by(auto)

   144     have "0 : ?N  A" and "?n - 1 : ?N  A"  using card A \<ge> 2 by simp+

   145     then obtain a b where ab: "a:A" "b:A" and Na: "?N a = 0" and Nb: "?N b = ?n - 1"

   146       by (auto simp del: 2)

   147     have "a \<noteq> b" using Na Nb card A \<ge> 2 by auto

   148     have "R  {a} - {a} = {}" by (metis 1 Na ab card_eq_0_iff finite_Diff)

   149     hence "b \<notin> R  {a}" using a\<noteq>b by blast

   150     hence "a \<notin> R  {b}" by (metis Image_singleton_iff assms(2) sym_def)

   151     hence 3: "R  {b} - {b} <= A - {a,b}" using 0 ab by blast

   152     have 4: "finite (A - {a,b})" using finite A by simp

   153     have "?N b <= ?n - 2" using ab a\<noteq>b finite A card_mono[OF 4 3] by simp

   154     then show False using Nb card A \<ge>  2 by arith

   155   qed

   156 qed

   157

   158 text {*

   159   From W. W. Bledsoe and Guohui Feng, SET-VAR. JAR 11 (3), 1993, pages

   160   293-314.

   161

   162   Isabelle can prove the easy examples without any special mechanisms,

   163   but it can't prove the hard ones.

   164 *}

   165

   166 lemma "\<exists>A. (\<forall>x \<in> A. x \<le> (0::int))"

   167   -- {* Example 1, page 295. *}

   168   by force

   169

   170 lemma "D \<in> F \<Longrightarrow> \<exists>G. \<forall>A \<in> G. \<exists>B \<in> F. A \<subseteq> B"

   171   -- {* Example 2. *}

   172   by force

   173

   174 lemma "P a \<Longrightarrow> \<exists>A. (\<forall>x \<in> A. P x) \<and> (\<exists>y. y \<in> A)"

   175   -- {* Example 3. *}

   176   by force

   177

   178 lemma "a < b \<and> b < (c::int) \<Longrightarrow> \<exists>A. a \<notin> A \<and> b \<in> A \<and> c \<notin> A"

   179   -- {* Example 4. *}

   180   by force

   181

   182 lemma "P (f b) \<Longrightarrow> \<exists>s A. (\<forall>x \<in> A. P x) \<and> f s \<in> A"

   183   -- {*Example 5, page 298. *}

   184   by force

   185

   186 lemma "P (f b) \<Longrightarrow> \<exists>s A. (\<forall>x \<in> A. P x) \<and> f s \<in> A"

   187   -- {* Example 6. *}

   188   by force

   189

   190 lemma "\<exists>A. a \<notin> A"

   191   -- {* Example 7. *}

   192   by force

   193

   194 lemma "(\<forall>u v. u < (0::int) \<longrightarrow> u \<noteq> abs v)

   195     \<longrightarrow> (\<exists>A::int set. (\<forall>y. abs y \<notin> A) \<and> -2 \<in> A)"

   196   -- {* Example 8 now needs a small hint. *}

   197   by (simp add: abs_if, force)

   198     -- {* not @{text blast}, which can't simplify @{text "-2 < 0"} *}

   199

   200 text {* Example 9 omitted (requires the reals). *}

   201

   202 text {* The paper has no Example 10! *}

   203

   204 lemma "(\<forall>A. 0 \<in> A \<and> (\<forall>x \<in> A. Suc x \<in> A) \<longrightarrow> n \<in> A) \<and>

   205   P 0 \<and> (\<forall>x. P x \<longrightarrow> P (Suc x)) \<longrightarrow> P n"

   206   -- {* Example 11: needs a hint. *}

   207 by(metis nat.induct)

   208

   209 lemma

   210   "(\<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)

   211     \<and> P n \<longrightarrow> P m"

   212   -- {* Example 12. *}

   213   by auto

   214

   215 lemma

   216   "(\<forall>x. (\<exists>u. x = 2 * u) = (\<not> (\<exists>v. Suc x = 2 * v))) \<longrightarrow>

   217     (\<exists>A. \<forall>x. (x \<in> A) = (Suc x \<notin> A))"

   218   -- {* Example EO1: typo in article, and with the obvious fix it seems

   219       to require arithmetic reasoning. *}

   220   apply clarify

   221   apply (rule_tac x = "{x. \<exists>u. x = 2 * u}" in exI, auto)

   222    apply metis+

   223   done

   224

   225 end
`