src/HOL/ex/set.thy
author paulson
Wed Feb 02 18:06:25 2005 +0100 (2005-02-02)
changeset 15488 7c638a46dcbb
parent 15481 fc075ae929e4
child 16417 9bc16273c2d4
permissions -rw-r--r--
tidying of some subst/simplesubst proofs
paulson@13058
     1
(*  Title:      HOL/ex/set.thy
paulson@13058
     2
    ID:         $Id$
paulson@13058
     3
    Author:     Tobias Nipkow and Lawrence C Paulson
paulson@13058
     4
    Copyright   1991  University of Cambridge
wenzelm@13107
     5
*)
paulson@13058
     6
wenzelm@13107
     7
header {* Set Theory examples: Cantor's Theorem, Schröder-Berstein Theorem, etc. *}
wenzelm@9100
     8
wenzelm@9100
     9
theory set = Main:
wenzelm@9100
    10
wenzelm@13107
    11
text{*
wenzelm@13107
    12
  These two are cited in Benzmueller and Kohlhase's system description
wenzelm@13107
    13
  of LEO, CADE-15, 1998 (pages 139-143) as theorems LEO could not
wenzelm@13107
    14
  prove.
wenzelm@13107
    15
*}
paulson@13058
    16
wenzelm@13107
    17
lemma "(X = Y \<union> Z) =
wenzelm@13107
    18
    (Y \<subseteq> X \<and> Z \<subseteq> X \<and> (\<forall>V. Y \<subseteq> V \<and> Z \<subseteq> V \<longrightarrow> X \<subseteq> V))"
wenzelm@13107
    19
  by blast
paulson@13058
    20
wenzelm@13107
    21
lemma "(X = Y \<inter> Z) =
wenzelm@13107
    22
    (X \<subseteq> Y \<and> X \<subseteq> Z \<and> (\<forall>V. V \<subseteq> Y \<and> V \<subseteq> Z \<longrightarrow> V \<subseteq> X))"
wenzelm@13107
    23
  by blast
paulson@13058
    24
wenzelm@13107
    25
text {*
wenzelm@13107
    26
  Trivial example of term synthesis: apparently hard for some provers!
wenzelm@13107
    27
*}
paulson@13058
    28
wenzelm@13107
    29
lemma "a \<noteq> b \<Longrightarrow> a \<in> ?X \<and> b \<notin> ?X"
wenzelm@13107
    30
  by blast
wenzelm@13107
    31
wenzelm@13107
    32
wenzelm@13107
    33
subsection {* Examples for the @{text blast} paper *}
paulson@13058
    34
wenzelm@13107
    35
lemma "(\<Union>x \<in> C. f x \<union> g x) = \<Union>(f ` C)  \<union>  \<Union>(g ` C)"
wenzelm@13107
    36
  -- {* Union-image, called @{text Un_Union_image} in Main HOL *}
wenzelm@13107
    37
  by blast
paulson@13058
    38
wenzelm@13107
    39
lemma "(\<Inter>x \<in> C. f x \<inter> g x) = \<Inter>(f ` C) \<inter> \<Inter>(g ` C)"
wenzelm@13107
    40
  -- {* Inter-image, called @{text Int_Inter_image} in Main HOL *}
wenzelm@13107
    41
  by blast
paulson@13058
    42
wenzelm@13107
    43
lemma "\<And>S::'a set set. \<forall>x \<in> S. \<forall>y \<in> S. x \<subseteq> y \<Longrightarrow> \<exists>z. S \<subseteq> {z}"
wenzelm@13107
    44
  -- {* Singleton I.  Nice demonstration of @{text blast}--and its limitations. *}
wenzelm@13107
    45
  -- {* For some unfathomable reason, @{text UNIV_I} increases the search space greatly. *}
wenzelm@13107
    46
  by (blast del: UNIV_I)
paulson@13058
    47
wenzelm@13107
    48
lemma "\<forall>x \<in> S. \<Union>S \<subseteq> x \<Longrightarrow> \<exists>z. S \<subseteq> {z}"
wenzelm@13107
    49
  -- {*Singleton II.  Variant of the benchmark above. *}
wenzelm@13107
    50
  by (blast del: UNIV_I)
wenzelm@13107
    51
wenzelm@13107
    52
lemma "\<exists>!x. f (g x) = x \<Longrightarrow> \<exists>!y. g (f y) = y"
wenzelm@13107
    53
  -- {* A unique fixpoint theorem --- @{text fast}/@{text best}/@{text meson} all fail. *}
wenzelm@13107
    54
  apply (erule ex1E, rule ex1I, erule arg_cong)
wenzelm@13107
    55
  apply (rule subst, assumption, erule allE, rule arg_cong, erule mp)
wenzelm@13107
    56
  apply (erule arg_cong)
wenzelm@13107
    57
  done
paulson@13058
    58
paulson@13058
    59
paulson@13058
    60
wenzelm@13107
    61
subsection {* Cantor's Theorem: There is no surjection from a set to its powerset *}
paulson@13058
    62
wenzelm@13107
    63
lemma cantor1: "\<not> (\<exists>f:: 'a \<Rightarrow> 'a set. \<forall>S. \<exists>x. f x = S)"
wenzelm@13107
    64
  -- {* Requires best-first search because it is undirectional. *}
wenzelm@13107
    65
  by best
paulson@13058
    66
wenzelm@13107
    67
lemma "\<forall>f:: 'a \<Rightarrow> 'a set. \<forall>x. f x \<noteq> ?S f"
wenzelm@13107
    68
  -- {*This form displays the diagonal term. *}
wenzelm@13107
    69
  by best
paulson@13058
    70
wenzelm@13107
    71
lemma "?S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
wenzelm@13107
    72
  -- {* This form exploits the set constructs. *}
wenzelm@13107
    73
  by (rule notI, erule rangeE, best)
paulson@13058
    74
wenzelm@13107
    75
lemma "?S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
wenzelm@13107
    76
  -- {* Or just this! *}
wenzelm@13107
    77
  by best
wenzelm@13107
    78
paulson@13058
    79
wenzelm@13107
    80
subsection {* The Schröder-Berstein Theorem *}
paulson@13058
    81
wenzelm@13107
    82
lemma disj_lemma: "- (f ` X) = g ` (-X) \<Longrightarrow> f a = g b \<Longrightarrow> a \<in> X \<Longrightarrow> b \<in> X"
wenzelm@13107
    83
  by blast
paulson@13058
    84
paulson@13058
    85
lemma surj_if_then_else:
wenzelm@13107
    86
  "-(f ` X) = g ` (-X) \<Longrightarrow> surj (\<lambda>z. if z \<in> X then f z else g z)"
wenzelm@13107
    87
  by (simp add: surj_def) blast
paulson@13058
    88
wenzelm@13107
    89
lemma bij_if_then_else:
wenzelm@13107
    90
  "inj_on f X \<Longrightarrow> inj_on g (-X) \<Longrightarrow> -(f ` X) = g ` (-X) \<Longrightarrow>
wenzelm@13107
    91
    h = (\<lambda>z. if z \<in> X then f z else g z) \<Longrightarrow> inj h \<and> surj h"
wenzelm@13107
    92
  apply (unfold inj_on_def)
wenzelm@13107
    93
  apply (simp add: surj_if_then_else)
wenzelm@13107
    94
  apply (blast dest: disj_lemma sym)
wenzelm@13107
    95
  done
paulson@13058
    96
wenzelm@13107
    97
lemma decomposition: "\<exists>X. X = - (g ` (- (f ` X)))"
wenzelm@13107
    98
  apply (rule exI)
wenzelm@13107
    99
  apply (rule lfp_unfold)
wenzelm@13107
   100
  apply (rule monoI, blast)
wenzelm@13107
   101
  done
paulson@13058
   102
wenzelm@13107
   103
theorem Schroeder_Bernstein:
wenzelm@13107
   104
  "inj (f :: 'a \<Rightarrow> 'b) \<Longrightarrow> inj (g :: 'b \<Rightarrow> 'a)
wenzelm@13107
   105
    \<Longrightarrow> \<exists>h:: 'a \<Rightarrow> 'b. inj h \<and> surj h"
paulson@15488
   106
  apply (rule decomposition [where f=f and g=g, THEN exE])
paulson@15488
   107
  apply (rule_tac x = "(\<lambda>z. if z \<in> x then f z else inv g z)" in exI) 
paulson@15488
   108
    --{*The term above can be synthesized by a sufficiently detailed proof.*}
wenzelm@13107
   109
  apply (rule bij_if_then_else)
wenzelm@13107
   110
     apply (rule_tac [4] refl)
wenzelm@13107
   111
    apply (rule_tac [2] inj_on_inv)
nipkow@15306
   112
    apply (erule subset_inj_on [OF _ subset_UNIV])
paulson@15488
   113
   apply blast
paulson@15488
   114
  apply (erule ssubst, subst double_complement, erule inv_image_comp [symmetric])
wenzelm@13107
   115
  done
paulson@13058
   116
paulson@13058
   117
wenzelm@13107
   118
text {*
wenzelm@13107
   119
  From W. W. Bledsoe and Guohui Feng, SET-VAR. JAR 11 (3), 1993, pages
wenzelm@13107
   120
  293-314.
wenzelm@13107
   121
wenzelm@13107
   122
  Isabelle can prove the easy examples without any special mechanisms,
wenzelm@13107
   123
  but it can't prove the hard ones.
paulson@13058
   124
*}
paulson@13058
   125
wenzelm@13107
   126
lemma "\<exists>A. (\<forall>x \<in> A. x \<le> (0::int))"
wenzelm@13107
   127
  -- {* Example 1, page 295. *}
wenzelm@13107
   128
  by force
paulson@13058
   129
wenzelm@13107
   130
lemma "D \<in> F \<Longrightarrow> \<exists>G. \<forall>A \<in> G. \<exists>B \<in> F. A \<subseteq> B"
wenzelm@13107
   131
  -- {* Example 2. *}
wenzelm@13107
   132
  by force
paulson@13058
   133
wenzelm@13107
   134
lemma "P a \<Longrightarrow> \<exists>A. (\<forall>x \<in> A. P x) \<and> (\<exists>y. y \<in> A)"
wenzelm@13107
   135
  -- {* Example 3. *}
wenzelm@13107
   136
  by force
paulson@13058
   137
wenzelm@13107
   138
lemma "a < b \<and> b < (c::int) \<Longrightarrow> \<exists>A. a \<notin> A \<and> b \<in> A \<and> c \<notin> A"
wenzelm@13107
   139
  -- {* Example 4. *}
wenzelm@13107
   140
  by force
paulson@13058
   141
wenzelm@13107
   142
lemma "P (f b) \<Longrightarrow> \<exists>s A. (\<forall>x \<in> A. P x) \<and> f s \<in> A"
wenzelm@13107
   143
  -- {*Example 5, page 298. *}
wenzelm@13107
   144
  by force
paulson@13058
   145
wenzelm@13107
   146
lemma "P (f b) \<Longrightarrow> \<exists>s A. (\<forall>x \<in> A. P x) \<and> f s \<in> A"
wenzelm@13107
   147
  -- {* Example 6. *}
wenzelm@13107
   148
  by force
paulson@13058
   149
wenzelm@13107
   150
lemma "\<exists>A. a \<notin> A"
wenzelm@13107
   151
  -- {* Example 7. *}
wenzelm@13107
   152
  by force
paulson@13058
   153
wenzelm@13107
   154
lemma "(\<forall>u v. u < (0::int) \<longrightarrow> u \<noteq> abs v)
wenzelm@13107
   155
    \<longrightarrow> (\<exists>A::int set. (\<forall>y. abs y \<notin> A) \<and> -2 \<in> A)"
paulson@14353
   156
  -- {* Example 8 now needs a small hint. *}
paulson@14353
   157
  by (simp add: abs_if, force)
paulson@14353
   158
    -- {* not @{text blast}, which can't simplify @{text "-2 < 0"} *}
paulson@13058
   159
wenzelm@13107
   160
text {* Example 9 omitted (requires the reals). *}
paulson@13058
   161
wenzelm@13107
   162
text {* The paper has no Example 10! *}
paulson@13058
   163
wenzelm@13107
   164
lemma "(\<forall>A. 0 \<in> A \<and> (\<forall>x \<in> A. Suc x \<in> A) \<longrightarrow> n \<in> A) \<and>
wenzelm@13107
   165
  P 0 \<and> (\<forall>x. P x \<longrightarrow> P (Suc x)) \<longrightarrow> P n"
wenzelm@13107
   166
  -- {* Example 11: needs a hint. *}
wenzelm@13107
   167
  apply clarify
wenzelm@13107
   168
  apply (drule_tac x = "{x. P x}" in spec)
wenzelm@13107
   169
  apply force
wenzelm@13107
   170
  done
paulson@13058
   171
wenzelm@13107
   172
lemma
wenzelm@13107
   173
  "(\<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)
wenzelm@13107
   174
    \<and> P n \<longrightarrow> P m"
wenzelm@13107
   175
  -- {* Example 12. *}
wenzelm@13107
   176
  by auto
paulson@13058
   177
wenzelm@13107
   178
lemma
wenzelm@13107
   179
  "(\<forall>x. (\<exists>u. x = 2 * u) = (\<not> (\<exists>v. Suc x = 2 * v))) \<longrightarrow>
wenzelm@13107
   180
    (\<exists>A. \<forall>x. (x \<in> A) = (Suc x \<notin> A))"
wenzelm@13107
   181
  -- {* Example EO1: typo in article, and with the obvious fix it seems
wenzelm@13107
   182
      to require arithmetic reasoning. *}
wenzelm@13107
   183
  apply clarify
wenzelm@13107
   184
  apply (rule_tac x = "{x. \<exists>u. x = 2 * u}" in exI, auto)
wenzelm@13107
   185
   apply (case_tac v, auto)
wenzelm@13107
   186
  apply (drule_tac x = "Suc v" and P = "\<lambda>x. ?a x \<noteq> ?b x" in spec, force)
wenzelm@13107
   187
  done
paulson@13058
   188
wenzelm@9100
   189
end