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