author | haftmann |
Thu, 18 Aug 2011 13:10:24 +0200 | |
changeset 44276 | fe769a0fcc96 |
parent 41460 | src/HOL/ex/set.thy@ea56b98aee83 |
child 45966 | 03ce2b2a29a2 |
permissions | -rw-r--r-- |
44276 | 1 |
(* Title: HOL/ex/Set_Theory.thy |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
2 |
Author: Tobias Nipkow and Lawrence C Paulson |
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
3 |
Copyright 1991 University of Cambridge |
13107 | 4 |
*) |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
5 |
|
40945 | 6 |
header {* Set Theory examples: Cantor's Theorem, Schröder-Bernstein Theorem, etc. *} |
9100 | 7 |
|
44276 | 8 |
theory Set_Theory |
9 |
imports Main |
|
10 |
begin |
|
9100 | 11 |
|
13107 | 12 |
text{* |
13 |
These two are cited in Benzmueller and Kohlhase's system description |
|
14 |
of LEO, CADE-15, 1998 (pages 139-143) as theorems LEO could not |
|
15 |
prove. |
|
16 |
*} |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
17 |
|
13107 | 18 |
lemma "(X = Y \<union> Z) = |
19 |
(Y \<subseteq> X \<and> Z \<subseteq> X \<and> (\<forall>V. Y \<subseteq> V \<and> Z \<subseteq> V \<longrightarrow> X \<subseteq> V))" |
|
20 |
by blast |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
21 |
|
13107 | 22 |
lemma "(X = Y \<inter> Z) = |
23 |
(X \<subseteq> Y \<and> X \<subseteq> Z \<and> (\<forall>V. V \<subseteq> Y \<and> V \<subseteq> Z \<longrightarrow> V \<subseteq> X))" |
|
24 |
by blast |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
25 |
|
13107 | 26 |
text {* |
27 |
Trivial example of term synthesis: apparently hard for some provers! |
|
28 |
*} |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
29 |
|
36319 | 30 |
schematic_lemma "a \<noteq> b \<Longrightarrow> a \<in> ?X \<and> b \<notin> ?X" |
13107 | 31 |
by blast |
32 |
||
33 |
||
34 |
subsection {* Examples for the @{text blast} paper *} |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
35 |
|
13107 | 36 |
lemma "(\<Union>x \<in> C. f x \<union> g x) = \<Union>(f ` C) \<union> \<Union>(g ` C)" |
37 |
-- {* Union-image, called @{text Un_Union_image} in Main HOL *} |
|
38 |
by blast |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
39 |
|
13107 | 40 |
lemma "(\<Inter>x \<in> C. f x \<inter> g x) = \<Inter>(f ` C) \<inter> \<Inter>(g ` C)" |
41 |
-- {* Inter-image, called @{text Int_Inter_image} in Main HOL *} |
|
42 |
by blast |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
43 |
|
16898 | 44 |
lemma singleton_example_1: |
45 |
"\<And>S::'a set set. \<forall>x \<in> S. \<forall>y \<in> S. x \<subseteq> y \<Longrightarrow> \<exists>z. S \<subseteq> {z}" |
|
18391 | 46 |
by blast |
16898 | 47 |
|
48 |
lemma singleton_example_2: |
|
49 |
"\<forall>x \<in> S. \<Union>S \<subseteq> x \<Longrightarrow> \<exists>z. S \<subseteq> {z}" |
|
50 |
-- {*Variant of the problem above. *} |
|
18391 | 51 |
by blast |
13107 | 52 |
|
53 |
lemma "\<exists>!x. f (g x) = x \<Longrightarrow> \<exists>!y. g (f y) = y" |
|
54 |
-- {* A unique fixpoint theorem --- @{text fast}/@{text best}/@{text meson} all fail. *} |
|
24573 | 55 |
by metis |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
56 |
|
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
57 |
|
13107 | 58 |
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:
9100
diff
changeset
|
59 |
|
13107 | 60 |
lemma cantor1: "\<not> (\<exists>f:: 'a \<Rightarrow> 'a set. \<forall>S. \<exists>x. f x = S)" |
61 |
-- {* Requires best-first search because it is undirectional. *} |
|
62 |
by best |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
63 |
|
36319 | 64 |
schematic_lemma "\<forall>f:: 'a \<Rightarrow> 'a set. \<forall>x. f x \<noteq> ?S f" |
13107 | 65 |
-- {*This form displays the diagonal term. *} |
66 |
by best |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
67 |
|
36319 | 68 |
schematic_lemma "?S \<notin> range (f :: 'a \<Rightarrow> 'a set)" |
13107 | 69 |
-- {* This form exploits the set constructs. *} |
70 |
by (rule notI, erule rangeE, best) |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
71 |
|
36319 | 72 |
schematic_lemma "?S \<notin> range (f :: 'a \<Rightarrow> 'a set)" |
13107 | 73 |
-- {* Or just this! *} |
74 |
by best |
|
75 |
||
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
76 |
|
40945 | 77 |
subsection {* The Schröder-Berstein Theorem *} |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
78 |
|
13107 | 79 |
lemma disj_lemma: "- (f ` X) = g ` (-X) \<Longrightarrow> f a = g b \<Longrightarrow> a \<in> X \<Longrightarrow> b \<in> X" |
80 |
by blast |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
81 |
|
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
82 |
lemma surj_if_then_else: |
13107 | 83 |
"-(f ` X) = g ` (-X) \<Longrightarrow> surj (\<lambda>z. if z \<in> X then f z else g z)" |
84 |
by (simp add: surj_def) blast |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
85 |
|
13107 | 86 |
lemma bij_if_then_else: |
87 |
"inj_on f X \<Longrightarrow> inj_on g (-X) \<Longrightarrow> -(f ` X) = g ` (-X) \<Longrightarrow> |
|
88 |
h = (\<lambda>z. if z \<in> X then f z else g z) \<Longrightarrow> inj h \<and> surj h" |
|
89 |
apply (unfold inj_on_def) |
|
90 |
apply (simp add: surj_if_then_else) |
|
91 |
apply (blast dest: disj_lemma sym) |
|
92 |
done |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
93 |
|
13107 | 94 |
lemma decomposition: "\<exists>X. X = - (g ` (- (f ` X)))" |
95 |
apply (rule exI) |
|
96 |
apply (rule lfp_unfold) |
|
97 |
apply (rule monoI, blast) |
|
98 |
done |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
99 |
|
13107 | 100 |
theorem Schroeder_Bernstein: |
101 |
"inj (f :: 'a \<Rightarrow> 'b) \<Longrightarrow> inj (g :: 'b \<Rightarrow> 'a) |
|
102 |
\<Longrightarrow> \<exists>h:: 'a \<Rightarrow> 'b. inj h \<and> surj h" |
|
15488 | 103 |
apply (rule decomposition [where f=f and g=g, THEN exE]) |
104 |
apply (rule_tac x = "(\<lambda>z. if z \<in> x then f z else inv g z)" in exI) |
|
105 |
--{*The term above can be synthesized by a sufficiently detailed proof.*} |
|
13107 | 106 |
apply (rule bij_if_then_else) |
107 |
apply (rule_tac [4] refl) |
|
33057 | 108 |
apply (rule_tac [2] inj_on_inv_into) |
15306 | 109 |
apply (erule subset_inj_on [OF _ subset_UNIV]) |
15488 | 110 |
apply blast |
111 |
apply (erule ssubst, subst double_complement, erule inv_image_comp [symmetric]) |
|
13107 | 112 |
done |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
113 |
|
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
114 |
|
24853 | 115 |
subsection {* A simple party theorem *} |
116 |
||
117 |
text{* \emph{At any party there are two people who know the same |
|
118 |
number of people}. Provided the party consists of at least two people |
|
119 |
and the knows relation is symmetric. Knowing yourself does not count |
|
120 |
--- otherwise knows needs to be reflexive. (From Freek Wiedijk's talk |
|
121 |
at TPHOLs 2007.) *} |
|
122 |
||
123 |
lemma equal_number_of_acquaintances: |
|
124 |
assumes "Domain R <= A" and "sym R" and "card A \<ge> 2" |
|
125 |
shows "\<not> inj_on (%a. card(R `` {a} - {a})) A" |
|
126 |
proof - |
|
127 |
let ?N = "%a. card(R `` {a} - {a})" |
|
128 |
let ?n = "card A" |
|
129 |
have "finite A" using `card A \<ge> 2` by(auto intro:ccontr) |
|
130 |
have 0: "R `` A <= A" using `sym R` `Domain R <= A` |
|
131 |
unfolding Domain_def sym_def by blast |
|
132 |
have h: "ALL a:A. R `` {a} <= A" using 0 by blast |
|
133 |
hence 1: "ALL a:A. finite(R `` {a})" using `finite A` |
|
134 |
by(blast intro: finite_subset) |
|
135 |
have sub: "?N ` A <= {0..<?n}" |
|
136 |
proof - |
|
137 |
have "ALL a:A. R `` {a} - {a} < A" using h by blast |
|
138 |
thus ?thesis using psubset_card_mono[OF `finite A`] by auto |
|
139 |
qed |
|
140 |
show "~ inj_on ?N A" (is "~ ?I") |
|
141 |
proof |
|
142 |
assume ?I |
|
143 |
hence "?n = card(?N ` A)" by(rule card_image[symmetric]) |
|
144 |
with sub `finite A` have 2[simp]: "?N ` A = {0..<?n}" |
|
145 |
using subset_card_intvl_is_intvl[of _ 0] by(auto) |
|
146 |
have "0 : ?N ` A" and "?n - 1 : ?N ` A" using `card A \<ge> 2` by simp+ |
|
147 |
then obtain a b where ab: "a:A" "b:A" and Na: "?N a = 0" and Nb: "?N b = ?n - 1" |
|
148 |
by (auto simp del: 2) |
|
149 |
have "a \<noteq> b" using Na Nb `card A \<ge> 2` by auto |
|
150 |
have "R `` {a} - {a} = {}" by (metis 1 Na ab card_eq_0_iff finite_Diff) |
|
151 |
hence "b \<notin> R `` {a}" using `a\<noteq>b` by blast |
|
152 |
hence "a \<notin> R `` {b}" by (metis Image_singleton_iff assms(2) sym_def) |
|
153 |
hence 3: "R `` {b} - {b} <= A - {a,b}" using 0 ab by blast |
|
154 |
have 4: "finite (A - {a,b})" using `finite A` by simp |
|
155 |
have "?N b <= ?n - 2" using ab `a\<noteq>b` `finite A` card_mono[OF 4 3] by simp |
|
156 |
then show False using Nb `card A \<ge> 2` by arith |
|
157 |
qed |
|
158 |
qed |
|
159 |
||
13107 | 160 |
text {* |
161 |
From W. W. Bledsoe and Guohui Feng, SET-VAR. JAR 11 (3), 1993, pages |
|
162 |
293-314. |
|
163 |
||
164 |
Isabelle can prove the easy examples without any special mechanisms, |
|
165 |
but it can't prove the hard ones. |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
166 |
*} |
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
167 |
|
13107 | 168 |
lemma "\<exists>A. (\<forall>x \<in> A. x \<le> (0::int))" |
169 |
-- {* Example 1, page 295. *} |
|
170 |
by force |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
171 |
|
13107 | 172 |
lemma "D \<in> F \<Longrightarrow> \<exists>G. \<forall>A \<in> G. \<exists>B \<in> F. A \<subseteq> B" |
173 |
-- {* Example 2. *} |
|
174 |
by force |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
175 |
|
13107 | 176 |
lemma "P a \<Longrightarrow> \<exists>A. (\<forall>x \<in> A. P x) \<and> (\<exists>y. y \<in> A)" |
177 |
-- {* Example 3. *} |
|
178 |
by force |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
179 |
|
13107 | 180 |
lemma "a < b \<and> b < (c::int) \<Longrightarrow> \<exists>A. a \<notin> A \<and> b \<in> A \<and> c \<notin> A" |
181 |
-- {* Example 4. *} |
|
182 |
by force |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
183 |
|
13107 | 184 |
lemma "P (f b) \<Longrightarrow> \<exists>s A. (\<forall>x \<in> A. P x) \<and> f s \<in> A" |
185 |
-- {*Example 5, page 298. *} |
|
186 |
by force |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
187 |
|
13107 | 188 |
lemma "P (f b) \<Longrightarrow> \<exists>s A. (\<forall>x \<in> A. P x) \<and> f s \<in> A" |
189 |
-- {* Example 6. *} |
|
190 |
by force |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
191 |
|
13107 | 192 |
lemma "\<exists>A. a \<notin> A" |
193 |
-- {* Example 7. *} |
|
194 |
by force |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
195 |
|
13107 | 196 |
lemma "(\<forall>u v. u < (0::int) \<longrightarrow> u \<noteq> abs v) |
197 |
\<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:
13107
diff
changeset
|
198 |
-- {* Example 8 now needs a small hint. *} |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
13107
diff
changeset
|
199 |
by (simp add: abs_if, force) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
13107
diff
changeset
|
200 |
-- {* 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:
9100
diff
changeset
|
201 |
|
13107 | 202 |
text {* Example 9 omitted (requires the reals). *} |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
203 |
|
13107 | 204 |
text {* The paper has no Example 10! *} |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
205 |
|
13107 | 206 |
lemma "(\<forall>A. 0 \<in> A \<and> (\<forall>x \<in> A. Suc x \<in> A) \<longrightarrow> n \<in> A) \<and> |
207 |
P 0 \<and> (\<forall>x. P x \<longrightarrow> P (Suc x)) \<longrightarrow> P n" |
|
208 |
-- {* Example 11: needs a hint. *} |
|
40928
ace26e2cee91
eliminated unqualified accesses of datatype facts -- it seems like they all of them were unintended
krauss
parents:
36319
diff
changeset
|
209 |
by(metis nat.induct) |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
210 |
|
13107 | 211 |
lemma |
212 |
"(\<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) |
|
213 |
\<and> P n \<longrightarrow> P m" |
|
214 |
-- {* Example 12. *} |
|
215 |
by auto |
|
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
216 |
|
13107 | 217 |
lemma |
218 |
"(\<forall>x. (\<exists>u. x = 2 * u) = (\<not> (\<exists>v. Suc x = 2 * v))) \<longrightarrow> |
|
219 |
(\<exists>A. \<forall>x. (x \<in> A) = (Suc x \<notin> A))" |
|
220 |
-- {* Example EO1: typo in article, and with the obvious fix it seems |
|
221 |
to require arithmetic reasoning. *} |
|
222 |
apply clarify |
|
223 |
apply (rule_tac x = "{x. \<exists>u. x = 2 * u}" in exI, auto) |
|
34055 | 224 |
apply metis+ |
13107 | 225 |
done |
13058
ad6106d7b4bb
converted theory "set" to Isar and added some SET-VAR examples
paulson
parents:
9100
diff
changeset
|
226 |
|
9100 | 227 |
end |