author | paulson |
Thu, 25 Mar 2004 10:32:21 +0100 | |
changeset 14485 | ea2707645af8 |
parent 14449 | d5c3d21df790 |
child 14504 | 7a3d80e276d4 |
permissions | -rw-r--r-- |
12396 | 1 |
(* Title: HOL/Finite_Set.thy |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
4 |
Additions by Jeremy Avigad in Feb 2004 |
12396 | 5 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
6 |
*) |
|
7 |
||
8 |
header {* Finite sets *} |
|
9 |
||
14485 | 10 |
theory Finite_Set = Divides + Power + Inductive: |
12396 | 11 |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
12 |
subsection {* Types Classes @{text plus_ac0} and @{text times_ac1} *} |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
13 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
14 |
axclass plus_ac0 < plus, zero |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
15 |
commute: "x + y = y + x" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
16 |
assoc: "(x + y) + z = x + (y + z)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
17 |
zero [simp]: "0 + x = x" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
18 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
19 |
lemma plus_ac0_left_commute: "x + (y+z) = y + ((x+z)::'a::plus_ac0)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
20 |
apply (rule plus_ac0.commute [THEN trans]) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
21 |
apply (rule plus_ac0.assoc [THEN trans]) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
22 |
apply (rule plus_ac0.commute [THEN arg_cong]) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
23 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
24 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
25 |
lemma plus_ac0_zero_right [simp]: "x + 0 = (x ::'a::plus_ac0)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
26 |
apply (rule plus_ac0.commute [THEN trans]) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
27 |
apply (rule plus_ac0.zero) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
28 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
29 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
30 |
lemmas plus_ac0 = plus_ac0.assoc plus_ac0.commute plus_ac0_left_commute |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
31 |
plus_ac0.zero plus_ac0_zero_right |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
32 |
|
14449 | 33 |
instance almost_semiring < plus_ac0 |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
34 |
proof qed (rule add_commute add_assoc almost_semiring.add_0)+ |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
35 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
36 |
axclass times_ac1 < times, one |
14485 | 37 |
commute: "x * y = y * x" |
38 |
assoc: "(x * y) * z = x * (y * z)" |
|
39 |
one [simp]: "1 * x = x" |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
40 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
41 |
theorem times_ac1_left_commute: "(x::'a::times_ac1) * ((y::'a) * z) = |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
42 |
y * (x * z)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
43 |
proof - |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
44 |
have "(x::'a::times_ac1) * (y * z) = (x * y) * z" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
45 |
by (rule times_ac1.assoc [THEN sym]) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
46 |
also have "x * y = y * x" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
47 |
by (rule times_ac1.commute) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
48 |
also have "(y * x) * z = y * (x * z)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
49 |
by (rule times_ac1.assoc) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
50 |
finally show ?thesis . |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
51 |
qed |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
52 |
|
14485 | 53 |
theorem times_ac1_one_right [simp]: "(x::'a::times_ac1) * 1 = x" |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
54 |
proof - |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
55 |
have "x * 1 = 1 * x" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
56 |
by (rule times_ac1.commute) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
57 |
also have "... = x" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
58 |
by (rule times_ac1.one) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
59 |
finally show ?thesis . |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
60 |
qed |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
61 |
|
14449 | 62 |
instance almost_semiring < times_ac1 |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
63 |
apply intro_classes |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
64 |
apply (rule mult_commute) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
65 |
apply (rule mult_assoc, simp) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
66 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
67 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
68 |
theorems times_ac1 = times_ac1.assoc times_ac1.commute times_ac1_left_commute |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
69 |
times_ac1.one times_ac1_one_right |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
70 |
|
12396 | 71 |
subsection {* Collection of finite sets *} |
72 |
||
73 |
consts Finites :: "'a set set" |
|
13737 | 74 |
syntax |
75 |
finite :: "'a set => bool" |
|
76 |
translations |
|
77 |
"finite A" == "A : Finites" |
|
12396 | 78 |
|
79 |
inductive Finites |
|
80 |
intros |
|
81 |
emptyI [simp, intro!]: "{} : Finites" |
|
82 |
insertI [simp, intro!]: "A : Finites ==> insert a A : Finites" |
|
83 |
||
84 |
axclass finite \<subseteq> type |
|
85 |
finite: "finite UNIV" |
|
86 |
||
13737 | 87 |
lemma ex_new_if_finite: -- "does not depend on def of finite at all" |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
88 |
"[| ~finite(UNIV::'a set); finite A |] ==> \<exists>a::'a. a \<notin> A" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
89 |
by(subgoal_tac "A \<noteq> UNIV", blast, blast) |
13737 | 90 |
|
12396 | 91 |
|
92 |
lemma finite_induct [case_names empty insert, induct set: Finites]: |
|
93 |
"finite F ==> |
|
94 |
P {} ==> (!!F x. finite F ==> x \<notin> F ==> P F ==> P (insert x F)) ==> P F" |
|
95 |
-- {* Discharging @{text "x \<notin> F"} entails extra work. *} |
|
96 |
proof - |
|
13421 | 97 |
assume "P {}" and |
98 |
insert: "!!F x. finite F ==> x \<notin> F ==> P F ==> P (insert x F)" |
|
12396 | 99 |
assume "finite F" |
100 |
thus "P F" |
|
101 |
proof induct |
|
102 |
show "P {}" . |
|
103 |
fix F x assume F: "finite F" and P: "P F" |
|
104 |
show "P (insert x F)" |
|
105 |
proof cases |
|
106 |
assume "x \<in> F" |
|
107 |
hence "insert x F = F" by (rule insert_absorb) |
|
108 |
with P show ?thesis by (simp only:) |
|
109 |
next |
|
110 |
assume "x \<notin> F" |
|
111 |
from F this P show ?thesis by (rule insert) |
|
112 |
qed |
|
113 |
qed |
|
114 |
qed |
|
115 |
||
116 |
lemma finite_subset_induct [consumes 2, case_names empty insert]: |
|
117 |
"finite F ==> F \<subseteq> A ==> |
|
118 |
P {} ==> (!!F a. finite F ==> a \<in> A ==> a \<notin> F ==> P F ==> P (insert a F)) ==> |
|
119 |
P F" |
|
120 |
proof - |
|
13421 | 121 |
assume "P {}" and insert: |
122 |
"!!F a. finite F ==> a \<in> A ==> a \<notin> F ==> P F ==> P (insert a F)" |
|
12396 | 123 |
assume "finite F" |
124 |
thus "F \<subseteq> A ==> P F" |
|
125 |
proof induct |
|
126 |
show "P {}" . |
|
127 |
fix F x assume "finite F" and "x \<notin> F" |
|
128 |
and P: "F \<subseteq> A ==> P F" and i: "insert x F \<subseteq> A" |
|
129 |
show "P (insert x F)" |
|
130 |
proof (rule insert) |
|
131 |
from i show "x \<in> A" by blast |
|
132 |
from i have "F \<subseteq> A" by blast |
|
133 |
with P show "P F" . |
|
134 |
qed |
|
135 |
qed |
|
136 |
qed |
|
137 |
||
138 |
lemma finite_UnI: "finite F ==> finite G ==> finite (F Un G)" |
|
139 |
-- {* The union of two finite sets is finite. *} |
|
140 |
by (induct set: Finites) simp_all |
|
141 |
||
142 |
lemma finite_subset: "A \<subseteq> B ==> finite B ==> finite A" |
|
143 |
-- {* Every subset of a finite set is finite. *} |
|
144 |
proof - |
|
145 |
assume "finite B" |
|
146 |
thus "!!A. A \<subseteq> B ==> finite A" |
|
147 |
proof induct |
|
148 |
case empty |
|
149 |
thus ?case by simp |
|
150 |
next |
|
151 |
case (insert F x A) |
|
152 |
have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F ==> finite (A - {x})" . |
|
153 |
show "finite A" |
|
154 |
proof cases |
|
155 |
assume x: "x \<in> A" |
|
156 |
with A have "A - {x} \<subseteq> F" by (simp add: subset_insert_iff) |
|
157 |
with r have "finite (A - {x})" . |
|
158 |
hence "finite (insert x (A - {x}))" .. |
|
159 |
also have "insert x (A - {x}) = A" by (rule insert_Diff) |
|
160 |
finally show ?thesis . |
|
161 |
next |
|
162 |
show "A \<subseteq> F ==> ?thesis" . |
|
163 |
assume "x \<notin> A" |
|
164 |
with A show "A \<subseteq> F" by (simp add: subset_insert_iff) |
|
165 |
qed |
|
166 |
qed |
|
167 |
qed |
|
168 |
||
169 |
lemma finite_Un [iff]: "finite (F Un G) = (finite F & finite G)" |
|
170 |
by (blast intro: finite_subset [of _ "X Un Y", standard] finite_UnI) |
|
171 |
||
172 |
lemma finite_Int [simp, intro]: "finite F | finite G ==> finite (F Int G)" |
|
173 |
-- {* The converse obviously fails. *} |
|
174 |
by (blast intro: finite_subset) |
|
175 |
||
176 |
lemma finite_insert [simp]: "finite (insert a A) = finite A" |
|
177 |
apply (subst insert_is_Un) |
|
14208 | 178 |
apply (simp only: finite_Un, blast) |
12396 | 179 |
done |
180 |
||
181 |
lemma finite_empty_induct: |
|
182 |
"finite A ==> |
|
183 |
P A ==> (!!a A. finite A ==> a:A ==> P A ==> P (A - {a})) ==> P {}" |
|
184 |
proof - |
|
185 |
assume "finite A" |
|
186 |
and "P A" and "!!a A. finite A ==> a:A ==> P A ==> P (A - {a})" |
|
187 |
have "P (A - A)" |
|
188 |
proof - |
|
189 |
fix c b :: "'a set" |
|
190 |
presume c: "finite c" and b: "finite b" |
|
191 |
and P1: "P b" and P2: "!!x y. finite y ==> x \<in> y ==> P y ==> P (y - {x})" |
|
192 |
from c show "c \<subseteq> b ==> P (b - c)" |
|
193 |
proof induct |
|
194 |
case empty |
|
195 |
from P1 show ?case by simp |
|
196 |
next |
|
197 |
case (insert F x) |
|
198 |
have "P (b - F - {x})" |
|
199 |
proof (rule P2) |
|
200 |
from _ b show "finite (b - F)" by (rule finite_subset) blast |
|
201 |
from insert show "x \<in> b - F" by simp |
|
202 |
from insert show "P (b - F)" by simp |
|
203 |
qed |
|
204 |
also have "b - F - {x} = b - insert x F" by (rule Diff_insert [symmetric]) |
|
205 |
finally show ?case . |
|
206 |
qed |
|
207 |
next |
|
208 |
show "A \<subseteq> A" .. |
|
209 |
qed |
|
210 |
thus "P {}" by simp |
|
211 |
qed |
|
212 |
||
213 |
lemma finite_Diff [simp]: "finite B ==> finite (B - Ba)" |
|
214 |
by (rule Diff_subset [THEN finite_subset]) |
|
215 |
||
216 |
lemma finite_Diff_insert [iff]: "finite (A - insert a B) = finite (A - B)" |
|
217 |
apply (subst Diff_insert) |
|
218 |
apply (case_tac "a : A - B") |
|
219 |
apply (rule finite_insert [symmetric, THEN trans]) |
|
14208 | 220 |
apply (subst insert_Diff, simp_all) |
12396 | 221 |
done |
222 |
||
223 |
||
13825 | 224 |
subsubsection {* Image and Inverse Image over Finite Sets *} |
225 |
||
226 |
lemma finite_imageI[simp]: "finite F ==> finite (h ` F)" |
|
227 |
-- {* The image of a finite set is finite. *} |
|
228 |
by (induct set: Finites) simp_all |
|
229 |
||
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
230 |
lemma finite_surj: "finite A ==> B <= f ` A ==> finite B" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
231 |
apply (frule finite_imageI) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
232 |
apply (erule finite_subset, assumption) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
233 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
234 |
|
13825 | 235 |
lemma finite_range_imageI: |
236 |
"finite (range g) ==> finite (range (%x. f (g x)))" |
|
14208 | 237 |
apply (drule finite_imageI, simp) |
13825 | 238 |
done |
239 |
||
12396 | 240 |
lemma finite_imageD: "finite (f`A) ==> inj_on f A ==> finite A" |
241 |
proof - |
|
242 |
have aux: "!!A. finite (A - {}) = finite A" by simp |
|
243 |
fix B :: "'a set" |
|
244 |
assume "finite B" |
|
245 |
thus "!!A. f`A = B ==> inj_on f A ==> finite A" |
|
246 |
apply induct |
|
247 |
apply simp |
|
248 |
apply (subgoal_tac "EX y:A. f y = x & F = f ` (A - {y})") |
|
249 |
apply clarify |
|
250 |
apply (simp (no_asm_use) add: inj_on_def) |
|
14208 | 251 |
apply (blast dest!: aux [THEN iffD1], atomize) |
12396 | 252 |
apply (erule_tac V = "ALL A. ?PP (A)" in thin_rl) |
14208 | 253 |
apply (frule subsetD [OF equalityD2 insertI1], clarify) |
12396 | 254 |
apply (rule_tac x = xa in bexI) |
255 |
apply (simp_all add: inj_on_image_set_diff) |
|
256 |
done |
|
257 |
qed (rule refl) |
|
258 |
||
259 |
||
13825 | 260 |
lemma inj_vimage_singleton: "inj f ==> f-`{a} \<subseteq> {THE x. f x = a}" |
261 |
-- {* The inverse image of a singleton under an injective function |
|
262 |
is included in a singleton. *} |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
263 |
apply (auto simp add: inj_on_def) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
264 |
apply (blast intro: the_equality [symmetric]) |
13825 | 265 |
done |
266 |
||
267 |
lemma finite_vimageI: "[|finite F; inj h|] ==> finite (h -` F)" |
|
268 |
-- {* The inverse image of a finite set under an injective function |
|
269 |
is finite. *} |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
270 |
apply (induct set: Finites, simp_all) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
271 |
apply (subst vimage_insert) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
272 |
apply (simp add: finite_Un finite_subset [OF inj_vimage_singleton]) |
13825 | 273 |
done |
274 |
||
275 |
||
12396 | 276 |
subsubsection {* The finite UNION of finite sets *} |
277 |
||
278 |
lemma finite_UN_I: "finite A ==> (!!a. a:A ==> finite (B a)) ==> finite (UN a:A. B a)" |
|
279 |
by (induct set: Finites) simp_all |
|
280 |
||
281 |
text {* |
|
282 |
Strengthen RHS to |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
283 |
@{prop "((ALL x:A. finite (B x)) & finite {x. x:A & B x \<noteq> {}})"}? |
12396 | 284 |
|
285 |
We'd need to prove |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
286 |
@{prop "finite C ==> ALL A B. (UNION A B) <= C --> finite {x. x:A & B x \<noteq> {}}"} |
12396 | 287 |
by induction. *} |
288 |
||
289 |
lemma finite_UN [simp]: "finite A ==> finite (UNION A B) = (ALL x:A. finite (B x))" |
|
290 |
by (blast intro: finite_UN_I finite_subset) |
|
291 |
||
292 |
||
293 |
subsubsection {* Sigma of finite sets *} |
|
294 |
||
295 |
lemma finite_SigmaI [simp]: |
|
296 |
"finite A ==> (!!a. a:A ==> finite (B a)) ==> finite (SIGMA a:A. B a)" |
|
297 |
by (unfold Sigma_def) (blast intro!: finite_UN_I) |
|
298 |
||
299 |
lemma finite_Prod_UNIV: |
|
300 |
"finite (UNIV::'a set) ==> finite (UNIV::'b set) ==> finite (UNIV::('a * 'b) set)" |
|
301 |
apply (subgoal_tac "(UNIV:: ('a * 'b) set) = Sigma UNIV (%x. UNIV)") |
|
302 |
apply (erule ssubst) |
|
14208 | 303 |
apply (erule finite_SigmaI, auto) |
12396 | 304 |
done |
305 |
||
306 |
instance unit :: finite |
|
307 |
proof |
|
308 |
have "finite {()}" by simp |
|
309 |
also have "{()} = UNIV" by auto |
|
310 |
finally show "finite (UNIV :: unit set)" . |
|
311 |
qed |
|
312 |
||
313 |
instance * :: (finite, finite) finite |
|
314 |
proof |
|
315 |
show "finite (UNIV :: ('a \<times> 'b) set)" |
|
316 |
proof (rule finite_Prod_UNIV) |
|
317 |
show "finite (UNIV :: 'a set)" by (rule finite) |
|
318 |
show "finite (UNIV :: 'b set)" by (rule finite) |
|
319 |
qed |
|
320 |
qed |
|
321 |
||
322 |
||
323 |
subsubsection {* The powerset of a finite set *} |
|
324 |
||
325 |
lemma finite_Pow_iff [iff]: "finite (Pow A) = finite A" |
|
326 |
proof |
|
327 |
assume "finite (Pow A)" |
|
328 |
with _ have "finite ((%x. {x}) ` A)" by (rule finite_subset) blast |
|
329 |
thus "finite A" by (rule finite_imageD [unfolded inj_on_def]) simp |
|
330 |
next |
|
331 |
assume "finite A" |
|
332 |
thus "finite (Pow A)" |
|
333 |
by induct (simp_all add: finite_UnI finite_imageI Pow_insert) |
|
334 |
qed |
|
335 |
||
336 |
lemma finite_converse [iff]: "finite (r^-1) = finite r" |
|
337 |
apply (subgoal_tac "r^-1 = (%(x,y). (y,x))`r") |
|
338 |
apply simp |
|
339 |
apply (rule iffI) |
|
340 |
apply (erule finite_imageD [unfolded inj_on_def]) |
|
341 |
apply (simp split add: split_split) |
|
342 |
apply (erule finite_imageI) |
|
14208 | 343 |
apply (simp add: converse_def image_def, auto) |
12396 | 344 |
apply (rule bexI) |
345 |
prefer 2 apply assumption |
|
346 |
apply simp |
|
347 |
done |
|
348 |
||
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
349 |
|
12396 | 350 |
subsubsection {* Finiteness of transitive closure *} |
351 |
||
352 |
text {* (Thanks to Sidi Ehmety) *} |
|
353 |
||
354 |
lemma finite_Field: "finite r ==> finite (Field r)" |
|
355 |
-- {* A finite relation has a finite field (@{text "= domain \<union> range"}. *} |
|
356 |
apply (induct set: Finites) |
|
357 |
apply (auto simp add: Field_def Domain_insert Range_insert) |
|
358 |
done |
|
359 |
||
360 |
lemma trancl_subset_Field2: "r^+ <= Field r \<times> Field r" |
|
361 |
apply clarify |
|
362 |
apply (erule trancl_induct) |
|
363 |
apply (auto simp add: Field_def) |
|
364 |
done |
|
365 |
||
366 |
lemma finite_trancl: "finite (r^+) = finite r" |
|
367 |
apply auto |
|
368 |
prefer 2 |
|
369 |
apply (rule trancl_subset_Field2 [THEN finite_subset]) |
|
370 |
apply (rule finite_SigmaI) |
|
371 |
prefer 3 |
|
13704
854501b1e957
Transitive closure is now defined inductively as well.
berghofe
parents:
13595
diff
changeset
|
372 |
apply (blast intro: r_into_trancl' finite_subset) |
12396 | 373 |
apply (auto simp add: finite_Field) |
374 |
done |
|
375 |
||
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
376 |
lemma finite_cartesian_product: "[| finite A; finite B |] ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
377 |
finite (A <*> B)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
378 |
by (rule finite_SigmaI) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
379 |
|
12396 | 380 |
|
381 |
subsection {* Finite cardinality *} |
|
382 |
||
383 |
text {* |
|
384 |
This definition, although traditional, is ugly to work with: @{text |
|
385 |
"card A == LEAST n. EX f. A = {f i | i. i < n}"}. Therefore we have |
|
386 |
switched to an inductive one: |
|
387 |
*} |
|
388 |
||
389 |
consts cardR :: "('a set \<times> nat) set" |
|
390 |
||
391 |
inductive cardR |
|
392 |
intros |
|
393 |
EmptyI: "({}, 0) : cardR" |
|
394 |
InsertI: "(A, n) : cardR ==> a \<notin> A ==> (insert a A, Suc n) : cardR" |
|
395 |
||
396 |
constdefs |
|
397 |
card :: "'a set => nat" |
|
398 |
"card A == THE n. (A, n) : cardR" |
|
399 |
||
400 |
inductive_cases cardR_emptyE: "({}, n) : cardR" |
|
401 |
inductive_cases cardR_insertE: "(insert a A,n) : cardR" |
|
402 |
||
403 |
lemma cardR_SucD: "(A, n) : cardR ==> a : A --> (EX m. n = Suc m)" |
|
404 |
by (induct set: cardR) simp_all |
|
405 |
||
406 |
lemma cardR_determ_aux1: |
|
407 |
"(A, m): cardR ==> (!!n a. m = Suc n ==> a:A ==> (A - {a}, n) : cardR)" |
|
14208 | 408 |
apply (induct set: cardR, auto) |
409 |
apply (simp add: insert_Diff_if, auto) |
|
12396 | 410 |
apply (drule cardR_SucD) |
411 |
apply (blast intro!: cardR.intros) |
|
412 |
done |
|
413 |
||
414 |
lemma cardR_determ_aux2: "(insert a A, Suc m) : cardR ==> a \<notin> A ==> (A, m) : cardR" |
|
415 |
by (drule cardR_determ_aux1) auto |
|
416 |
||
417 |
lemma cardR_determ: "(A, m): cardR ==> (!!n. (A, n) : cardR ==> n = m)" |
|
418 |
apply (induct set: cardR) |
|
419 |
apply (safe elim!: cardR_emptyE cardR_insertE) |
|
420 |
apply (rename_tac B b m) |
|
421 |
apply (case_tac "a = b") |
|
422 |
apply (subgoal_tac "A = B") |
|
14208 | 423 |
prefer 2 apply (blast elim: equalityE, blast) |
12396 | 424 |
apply (subgoal_tac "EX C. A = insert b C & B = insert a C") |
425 |
prefer 2 |
|
426 |
apply (rule_tac x = "A Int B" in exI) |
|
427 |
apply (blast elim: equalityE) |
|
428 |
apply (frule_tac A = B in cardR_SucD) |
|
429 |
apply (blast intro!: cardR.intros dest!: cardR_determ_aux2) |
|
430 |
done |
|
431 |
||
432 |
lemma cardR_imp_finite: "(A, n) : cardR ==> finite A" |
|
433 |
by (induct set: cardR) simp_all |
|
434 |
||
435 |
lemma finite_imp_cardR: "finite A ==> EX n. (A, n) : cardR" |
|
436 |
by (induct set: Finites) (auto intro!: cardR.intros) |
|
437 |
||
438 |
lemma card_equality: "(A,n) : cardR ==> card A = n" |
|
439 |
by (unfold card_def) (blast intro: cardR_determ) |
|
440 |
||
441 |
lemma card_empty [simp]: "card {} = 0" |
|
442 |
by (unfold card_def) (blast intro!: cardR.intros elim!: cardR_emptyE) |
|
443 |
||
444 |
lemma card_insert_disjoint [simp]: |
|
445 |
"finite A ==> x \<notin> A ==> card (insert x A) = Suc(card A)" |
|
446 |
proof - |
|
447 |
assume x: "x \<notin> A" |
|
448 |
hence aux: "!!n. ((insert x A, n) : cardR) = (EX m. (A, m) : cardR & n = Suc m)" |
|
449 |
apply (auto intro!: cardR.intros) |
|
450 |
apply (rule_tac A1 = A in finite_imp_cardR [THEN exE]) |
|
451 |
apply (force dest: cardR_imp_finite) |
|
452 |
apply (blast intro!: cardR.intros intro: cardR_determ) |
|
453 |
done |
|
454 |
assume "finite A" |
|
455 |
thus ?thesis |
|
456 |
apply (simp add: card_def aux) |
|
457 |
apply (rule the_equality) |
|
458 |
apply (auto intro: finite_imp_cardR |
|
459 |
cong: conj_cong simp: card_def [symmetric] card_equality) |
|
460 |
done |
|
461 |
qed |
|
462 |
||
463 |
lemma card_0_eq [simp]: "finite A ==> (card A = 0) = (A = {})" |
|
464 |
apply auto |
|
14208 | 465 |
apply (drule_tac a = x in mk_disjoint_insert, clarify) |
466 |
apply (rotate_tac -1, auto) |
|
12396 | 467 |
done |
468 |
||
469 |
lemma card_insert_if: |
|
470 |
"finite A ==> card (insert x A) = (if x:A then card A else Suc(card(A)))" |
|
471 |
by (simp add: insert_absorb) |
|
472 |
||
473 |
lemma card_Suc_Diff1: "finite A ==> x: A ==> Suc (card (A - {x})) = card A" |
|
14302 | 474 |
apply(rule_tac t = A in insert_Diff [THEN subst], assumption) |
475 |
apply(simp del:insert_Diff_single) |
|
476 |
done |
|
12396 | 477 |
|
478 |
lemma card_Diff_singleton: |
|
479 |
"finite A ==> x: A ==> card (A - {x}) = card A - 1" |
|
480 |
by (simp add: card_Suc_Diff1 [symmetric]) |
|
481 |
||
482 |
lemma card_Diff_singleton_if: |
|
483 |
"finite A ==> card (A-{x}) = (if x : A then card A - 1 else card A)" |
|
484 |
by (simp add: card_Diff_singleton) |
|
485 |
||
486 |
lemma card_insert: "finite A ==> card (insert x A) = Suc (card (A - {x}))" |
|
487 |
by (simp add: card_insert_if card_Suc_Diff1) |
|
488 |
||
489 |
lemma card_insert_le: "finite A ==> card A <= card (insert x A)" |
|
490 |
by (simp add: card_insert_if) |
|
491 |
||
492 |
lemma card_seteq: "finite B ==> (!!A. A <= B ==> card B <= card A ==> A = B)" |
|
14208 | 493 |
apply (induct set: Finites, simp, clarify) |
12396 | 494 |
apply (subgoal_tac "finite A & A - {x} <= F") |
14208 | 495 |
prefer 2 apply (blast intro: finite_subset, atomize) |
12396 | 496 |
apply (drule_tac x = "A - {x}" in spec) |
497 |
apply (simp add: card_Diff_singleton_if split add: split_if_asm) |
|
14208 | 498 |
apply (case_tac "card A", auto) |
12396 | 499 |
done |
500 |
||
501 |
lemma psubset_card_mono: "finite B ==> A < B ==> card A < card B" |
|
502 |
apply (simp add: psubset_def linorder_not_le [symmetric]) |
|
503 |
apply (blast dest: card_seteq) |
|
504 |
done |
|
505 |
||
506 |
lemma card_mono: "finite B ==> A <= B ==> card A <= card B" |
|
14208 | 507 |
apply (case_tac "A = B", simp) |
12396 | 508 |
apply (simp add: linorder_not_less [symmetric]) |
509 |
apply (blast dest: card_seteq intro: order_less_imp_le) |
|
510 |
done |
|
511 |
||
512 |
lemma card_Un_Int: "finite A ==> finite B |
|
513 |
==> card A + card B = card (A Un B) + card (A Int B)" |
|
14208 | 514 |
apply (induct set: Finites, simp) |
12396 | 515 |
apply (simp add: insert_absorb Int_insert_left) |
516 |
done |
|
517 |
||
518 |
lemma card_Un_disjoint: "finite A ==> finite B |
|
519 |
==> A Int B = {} ==> card (A Un B) = card A + card B" |
|
520 |
by (simp add: card_Un_Int) |
|
521 |
||
522 |
lemma card_Diff_subset: |
|
523 |
"finite A ==> B <= A ==> card A - card B = card (A - B)" |
|
524 |
apply (subgoal_tac "(A - B) Un B = A") |
|
525 |
prefer 2 apply blast |
|
14331 | 526 |
apply (rule nat_add_right_cancel [THEN iffD1]) |
12396 | 527 |
apply (rule card_Un_disjoint [THEN subst]) |
528 |
apply (erule_tac [4] ssubst) |
|
529 |
prefer 3 apply blast |
|
530 |
apply (simp_all add: add_commute not_less_iff_le |
|
531 |
add_diff_inverse card_mono finite_subset) |
|
532 |
done |
|
533 |
||
534 |
lemma card_Diff1_less: "finite A ==> x: A ==> card (A - {x}) < card A" |
|
535 |
apply (rule Suc_less_SucD) |
|
536 |
apply (simp add: card_Suc_Diff1) |
|
537 |
done |
|
538 |
||
539 |
lemma card_Diff2_less: |
|
540 |
"finite A ==> x: A ==> y: A ==> card (A - {x} - {y}) < card A" |
|
541 |
apply (case_tac "x = y") |
|
542 |
apply (simp add: card_Diff1_less) |
|
543 |
apply (rule less_trans) |
|
544 |
prefer 2 apply (auto intro!: card_Diff1_less) |
|
545 |
done |
|
546 |
||
547 |
lemma card_Diff1_le: "finite A ==> card (A - {x}) <= card A" |
|
548 |
apply (case_tac "x : A") |
|
549 |
apply (simp_all add: card_Diff1_less less_imp_le) |
|
550 |
done |
|
551 |
||
552 |
lemma card_psubset: "finite B ==> A \<subseteq> B ==> card A < card B ==> A < B" |
|
14208 | 553 |
by (erule psubsetI, blast) |
12396 | 554 |
|
555 |
||
556 |
subsubsection {* Cardinality of image *} |
|
557 |
||
558 |
lemma card_image_le: "finite A ==> card (f ` A) <= card A" |
|
14208 | 559 |
apply (induct set: Finites, simp) |
12396 | 560 |
apply (simp add: le_SucI finite_imageI card_insert_if) |
561 |
done |
|
562 |
||
563 |
lemma card_image: "finite A ==> inj_on f A ==> card (f ` A) = card A" |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
564 |
apply (induct set: Finites, simp_all, atomize, safe) |
14208 | 565 |
apply (unfold inj_on_def, blast) |
12396 | 566 |
apply (subst card_insert_disjoint) |
14208 | 567 |
apply (erule finite_imageI, blast, blast) |
12396 | 568 |
done |
569 |
||
570 |
lemma endo_inj_surj: "finite A ==> f ` A \<subseteq> A ==> inj_on f A ==> f ` A = A" |
|
571 |
by (simp add: card_seteq card_image) |
|
572 |
||
573 |
||
574 |
subsubsection {* Cardinality of the Powerset *} |
|
575 |
||
576 |
lemma card_Pow: "finite A ==> card (Pow A) = Suc (Suc 0) ^ card A" (* FIXME numeral 2 (!?) *) |
|
577 |
apply (induct set: Finites) |
|
578 |
apply (simp_all add: Pow_insert) |
|
14208 | 579 |
apply (subst card_Un_disjoint, blast) |
580 |
apply (blast intro: finite_imageI, blast) |
|
12396 | 581 |
apply (subgoal_tac "inj_on (insert x) (Pow F)") |
582 |
apply (simp add: card_image Pow_insert) |
|
583 |
apply (unfold inj_on_def) |
|
584 |
apply (blast elim!: equalityE) |
|
585 |
done |
|
586 |
||
587 |
text {* |
|
588 |
\medskip Relates to equivalence classes. Based on a theorem of |
|
589 |
F. Kammüller's. The @{prop "finite C"} premise is redundant. |
|
590 |
*} |
|
591 |
||
592 |
lemma dvd_partition: |
|
593 |
"finite C ==> finite (Union C) ==> |
|
594 |
ALL c : C. k dvd card c ==> |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
595 |
(ALL c1: C. ALL c2: C. c1 \<noteq> c2 --> c1 Int c2 = {}) ==> |
12396 | 596 |
k dvd card (Union C)" |
14208 | 597 |
apply (induct set: Finites, simp_all, clarify) |
12396 | 598 |
apply (subst card_Un_disjoint) |
599 |
apply (auto simp add: dvd_add disjoint_eq_subset_Compl) |
|
600 |
done |
|
601 |
||
602 |
||
603 |
subsection {* A fold functional for finite sets *} |
|
604 |
||
605 |
text {* |
|
606 |
For @{text n} non-negative we have @{text "fold f e {x1, ..., xn} = |
|
607 |
f x1 (... (f xn e))"} where @{text f} is at least left-commutative. |
|
608 |
*} |
|
609 |
||
610 |
consts |
|
611 |
foldSet :: "('b => 'a => 'a) => 'a => ('b set \<times> 'a) set" |
|
612 |
||
613 |
inductive "foldSet f e" |
|
614 |
intros |
|
615 |
emptyI [intro]: "({}, e) : foldSet f e" |
|
616 |
insertI [intro]: "x \<notin> A ==> (A, y) : foldSet f e ==> (insert x A, f x y) : foldSet f e" |
|
617 |
||
618 |
inductive_cases empty_foldSetE [elim!]: "({}, x) : foldSet f e" |
|
619 |
||
620 |
constdefs |
|
621 |
fold :: "('b => 'a => 'a) => 'a => 'b set => 'a" |
|
622 |
"fold f e A == THE x. (A, x) : foldSet f e" |
|
623 |
||
624 |
lemma Diff1_foldSet: "(A - {x}, y) : foldSet f e ==> x: A ==> (A, f x y) : foldSet f e" |
|
14208 | 625 |
by (erule insert_Diff [THEN subst], rule foldSet.intros, auto) |
12396 | 626 |
|
627 |
lemma foldSet_imp_finite [simp]: "(A, x) : foldSet f e ==> finite A" |
|
628 |
by (induct set: foldSet) auto |
|
629 |
||
630 |
lemma finite_imp_foldSet: "finite A ==> EX x. (A, x) : foldSet f e" |
|
631 |
by (induct set: Finites) auto |
|
632 |
||
633 |
||
634 |
subsubsection {* Left-commutative operations *} |
|
635 |
||
636 |
locale LC = |
|
637 |
fixes f :: "'b => 'a => 'a" (infixl "\<cdot>" 70) |
|
638 |
assumes left_commute: "x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)" |
|
639 |
||
640 |
lemma (in LC) foldSet_determ_aux: |
|
641 |
"ALL A x. card A < n --> (A, x) : foldSet f e --> |
|
642 |
(ALL y. (A, y) : foldSet f e --> y = x)" |
|
643 |
apply (induct n) |
|
644 |
apply (auto simp add: less_Suc_eq) |
|
14208 | 645 |
apply (erule foldSet.cases, blast) |
646 |
apply (erule foldSet.cases, blast, clarify) |
|
12396 | 647 |
txt {* force simplification of @{text "card A < card (insert ...)"}. *} |
648 |
apply (erule rev_mp) |
|
649 |
apply (simp add: less_Suc_eq_le) |
|
650 |
apply (rule impI) |
|
651 |
apply (rename_tac Aa xa ya Ab xb yb, case_tac "xa = xb") |
|
652 |
apply (subgoal_tac "Aa = Ab") |
|
14208 | 653 |
prefer 2 apply (blast elim!: equalityE, blast) |
12396 | 654 |
txt {* case @{prop "xa \<notin> xb"}. *} |
655 |
apply (subgoal_tac "Aa - {xb} = Ab - {xa} & xb : Aa & xa : Ab") |
|
14208 | 656 |
prefer 2 apply (blast elim!: equalityE, clarify) |
12396 | 657 |
apply (subgoal_tac "Aa = insert xb Ab - {xa}") |
658 |
prefer 2 apply blast |
|
659 |
apply (subgoal_tac "card Aa <= card Ab") |
|
660 |
prefer 2 |
|
661 |
apply (rule Suc_le_mono [THEN subst]) |
|
662 |
apply (simp add: card_Suc_Diff1) |
|
663 |
apply (rule_tac A1 = "Aa - {xb}" and f1 = f in finite_imp_foldSet [THEN exE]) |
|
664 |
apply (blast intro: foldSet_imp_finite finite_Diff) |
|
665 |
apply (frule (1) Diff1_foldSet) |
|
666 |
apply (subgoal_tac "ya = f xb x") |
|
667 |
prefer 2 apply (blast del: equalityCE) |
|
668 |
apply (subgoal_tac "(Ab - {xa}, x) : foldSet f e") |
|
669 |
prefer 2 apply simp |
|
670 |
apply (subgoal_tac "yb = f xa x") |
|
671 |
prefer 2 apply (blast del: equalityCE dest: Diff1_foldSet) |
|
672 |
apply (simp (no_asm_simp) add: left_commute) |
|
673 |
done |
|
674 |
||
675 |
lemma (in LC) foldSet_determ: "(A, x) : foldSet f e ==> (A, y) : foldSet f e ==> y = x" |
|
676 |
by (blast intro: foldSet_determ_aux [rule_format]) |
|
677 |
||
678 |
lemma (in LC) fold_equality: "(A, y) : foldSet f e ==> fold f e A = y" |
|
679 |
by (unfold fold_def) (blast intro: foldSet_determ) |
|
680 |
||
681 |
lemma fold_empty [simp]: "fold f e {} = e" |
|
682 |
by (unfold fold_def) blast |
|
683 |
||
684 |
lemma (in LC) fold_insert_aux: "x \<notin> A ==> |
|
685 |
((insert x A, v) : foldSet f e) = |
|
686 |
(EX y. (A, y) : foldSet f e & v = f x y)" |
|
687 |
apply auto |
|
688 |
apply (rule_tac A1 = A and f1 = f in finite_imp_foldSet [THEN exE]) |
|
689 |
apply (fastsimp dest: foldSet_imp_finite) |
|
690 |
apply (blast intro: foldSet_determ) |
|
691 |
done |
|
692 |
||
693 |
lemma (in LC) fold_insert: |
|
694 |
"finite A ==> x \<notin> A ==> fold f e (insert x A) = f x (fold f e A)" |
|
695 |
apply (unfold fold_def) |
|
696 |
apply (simp add: fold_insert_aux) |
|
697 |
apply (rule the_equality) |
|
698 |
apply (auto intro: finite_imp_foldSet |
|
699 |
cong add: conj_cong simp add: fold_def [symmetric] fold_equality) |
|
700 |
done |
|
701 |
||
702 |
lemma (in LC) fold_commute: "finite A ==> (!!e. f x (fold f e A) = fold f (f x e) A)" |
|
14208 | 703 |
apply (induct set: Finites, simp) |
12396 | 704 |
apply (simp add: left_commute fold_insert) |
705 |
done |
|
706 |
||
707 |
lemma (in LC) fold_nest_Un_Int: |
|
708 |
"finite A ==> finite B |
|
709 |
==> fold f (fold f e B) A = fold f (fold f e (A Int B)) (A Un B)" |
|
14208 | 710 |
apply (induct set: Finites, simp) |
12396 | 711 |
apply (simp add: fold_insert fold_commute Int_insert_left insert_absorb) |
712 |
done |
|
713 |
||
714 |
lemma (in LC) fold_nest_Un_disjoint: |
|
715 |
"finite A ==> finite B ==> A Int B = {} |
|
716 |
==> fold f e (A Un B) = fold f (fold f e B) A" |
|
717 |
by (simp add: fold_nest_Un_Int) |
|
718 |
||
719 |
declare foldSet_imp_finite [simp del] |
|
720 |
empty_foldSetE [rule del] foldSet.intros [rule del] |
|
721 |
-- {* Delete rules to do with @{text foldSet} relation. *} |
|
722 |
||
723 |
||
724 |
||
725 |
subsubsection {* Commutative monoids *} |
|
726 |
||
727 |
text {* |
|
728 |
We enter a more restrictive context, with @{text "f :: 'a => 'a => 'a"} |
|
729 |
instead of @{text "'b => 'a => 'a"}. |
|
730 |
*} |
|
731 |
||
732 |
locale ACe = |
|
733 |
fixes f :: "'a => 'a => 'a" (infixl "\<cdot>" 70) |
|
734 |
and e :: 'a |
|
735 |
assumes ident [simp]: "x \<cdot> e = x" |
|
736 |
and commute: "x \<cdot> y = y \<cdot> x" |
|
737 |
and assoc: "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)" |
|
738 |
||
739 |
lemma (in ACe) left_commute: "x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)" |
|
740 |
proof - |
|
741 |
have "x \<cdot> (y \<cdot> z) = (y \<cdot> z) \<cdot> x" by (simp only: commute) |
|
742 |
also have "... = y \<cdot> (z \<cdot> x)" by (simp only: assoc) |
|
743 |
also have "z \<cdot> x = x \<cdot> z" by (simp only: commute) |
|
744 |
finally show ?thesis . |
|
745 |
qed |
|
746 |
||
12718 | 747 |
lemmas (in ACe) AC = assoc commute left_commute |
12396 | 748 |
|
12693 | 749 |
lemma (in ACe) left_ident [simp]: "e \<cdot> x = x" |
12396 | 750 |
proof - |
751 |
have "x \<cdot> e = x" by (rule ident) |
|
752 |
thus ?thesis by (subst commute) |
|
753 |
qed |
|
754 |
||
755 |
lemma (in ACe) fold_Un_Int: |
|
756 |
"finite A ==> finite B ==> |
|
757 |
fold f e A \<cdot> fold f e B = fold f e (A Un B) \<cdot> fold f e (A Int B)" |
|
14208 | 758 |
apply (induct set: Finites, simp) |
13400 | 759 |
apply (simp add: AC insert_absorb Int_insert_left |
13421 | 760 |
LC.fold_insert [OF LC.intro]) |
12396 | 761 |
done |
762 |
||
763 |
lemma (in ACe) fold_Un_disjoint: |
|
764 |
"finite A ==> finite B ==> A Int B = {} ==> |
|
765 |
fold f e (A Un B) = fold f e A \<cdot> fold f e B" |
|
766 |
by (simp add: fold_Un_Int) |
|
767 |
||
768 |
lemma (in ACe) fold_Un_disjoint2: |
|
769 |
"finite A ==> finite B ==> A Int B = {} ==> |
|
770 |
fold (f o g) e (A Un B) = fold (f o g) e A \<cdot> fold (f o g) e B" |
|
771 |
proof - |
|
772 |
assume b: "finite B" |
|
773 |
assume "finite A" |
|
774 |
thus "A Int B = {} ==> |
|
775 |
fold (f o g) e (A Un B) = fold (f o g) e A \<cdot> fold (f o g) e B" |
|
776 |
proof induct |
|
777 |
case empty |
|
778 |
thus ?case by simp |
|
779 |
next |
|
780 |
case (insert F x) |
|
13571 | 781 |
have "fold (f o g) e (insert x F \<union> B) = fold (f o g) e (insert x (F \<union> B))" |
12396 | 782 |
by simp |
13571 | 783 |
also have "... = (f o g) x (fold (f o g) e (F \<union> B))" |
13400 | 784 |
by (rule LC.fold_insert [OF LC.intro]) |
13421 | 785 |
(insert b insert, auto simp add: left_commute) |
13571 | 786 |
also from insert have "fold (f o g) e (F \<union> B) = |
787 |
fold (f o g) e F \<cdot> fold (f o g) e B" by blast |
|
788 |
also have "(f o g) x ... = (f o g) x (fold (f o g) e F) \<cdot> fold (f o g) e B" |
|
12396 | 789 |
by (simp add: AC) |
13571 | 790 |
also have "(f o g) x (fold (f o g) e F) = fold (f o g) e (insert x F)" |
13400 | 791 |
by (rule LC.fold_insert [OF LC.intro, symmetric]) (insert b insert, |
13421 | 792 |
auto simp add: left_commute) |
12396 | 793 |
finally show ?case . |
794 |
qed |
|
795 |
qed |
|
796 |
||
797 |
||
798 |
subsection {* Generalized summation over a set *} |
|
799 |
||
800 |
constdefs |
|
801 |
setsum :: "('a => 'b) => 'a set => 'b::plus_ac0" |
|
802 |
"setsum f A == if finite A then fold (op + o f) 0 A else 0" |
|
803 |
||
804 |
syntax |
|
805 |
"_setsum" :: "idt => 'a set => 'b => 'b::plus_ac0" ("\<Sum>_:_. _" [0, 51, 10] 10) |
|
806 |
syntax (xsymbols) |
|
807 |
"_setsum" :: "idt => 'a set => 'b => 'b::plus_ac0" ("\<Sum>_\<in>_. _" [0, 51, 10] 10) |
|
808 |
translations |
|
809 |
"\<Sum>i:A. b" == "setsum (%i. b) A" -- {* Beware of argument permutation! *} |
|
810 |
||
811 |
||
812 |
lemma setsum_empty [simp]: "setsum f {} = 0" |
|
813 |
by (simp add: setsum_def) |
|
814 |
||
815 |
lemma setsum_insert [simp]: |
|
816 |
"finite F ==> a \<notin> F ==> setsum f (insert a F) = f a + setsum f F" |
|
13365 | 817 |
by (simp add: setsum_def |
13421 | 818 |
LC.fold_insert [OF LC.intro] plus_ac0_left_commute) |
12396 | 819 |
|
14485 | 820 |
lemma setsum_reindex [rule_format]: "finite B ==> |
821 |
inj_on f B --> setsum h (f ` B) = setsum (h \<circ> f) B" |
|
822 |
apply (rule finite_induct, assumption, force) |
|
823 |
apply (rule impI, auto) |
|
824 |
apply (simp add: inj_on_def) |
|
825 |
apply (subgoal_tac "f x \<notin> f ` F") |
|
826 |
apply (subgoal_tac "finite (f ` F)") |
|
827 |
apply (auto simp add: setsum_insert) |
|
828 |
apply (simp add: inj_on_def) |
|
12396 | 829 |
done |
830 |
||
14485 | 831 |
lemma setsum_reindex_id: "finite B ==> inj_on f B ==> |
832 |
setsum f B = setsum id (f ` B)" |
|
833 |
by (auto simp add: setsum_reindex id_o) |
|
12396 | 834 |
|
14485 | 835 |
lemma setsum_reindex_cong: "finite A ==> inj_on f A ==> |
836 |
B = f ` A ==> g = h \<circ> f ==> setsum h B = setsum g A" |
|
837 |
by (frule setsum_reindex, assumption, simp) |
|
12396 | 838 |
|
839 |
lemma setsum_cong: |
|
840 |
"A = B ==> (!!x. x:B ==> f x = g x) ==> setsum f A = setsum g B" |
|
841 |
apply (case_tac "finite B") |
|
14208 | 842 |
prefer 2 apply (simp add: setsum_def, simp) |
12396 | 843 |
apply (subgoal_tac "ALL C. C <= B --> (ALL x:C. f x = g x) --> setsum f C = setsum g C") |
844 |
apply simp |
|
14208 | 845 |
apply (erule finite_induct, simp) |
846 |
apply (simp add: subset_insert_iff, clarify) |
|
12396 | 847 |
apply (subgoal_tac "finite C") |
848 |
prefer 2 apply (blast dest: finite_subset [COMP swap_prems_rl]) |
|
849 |
apply (subgoal_tac "C = insert x (C - {x})") |
|
850 |
prefer 2 apply blast |
|
851 |
apply (erule ssubst) |
|
852 |
apply (drule spec) |
|
853 |
apply (erule (1) notE impE) |
|
14302 | 854 |
apply (simp add: Ball_def del:insert_Diff_single) |
12396 | 855 |
done |
856 |
||
14485 | 857 |
lemma setsum_0: "setsum (%i. 0) A = 0" |
858 |
apply (case_tac "finite A") |
|
859 |
prefer 2 apply (simp add: setsum_def) |
|
860 |
apply (erule finite_induct, auto) |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
861 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
862 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
863 |
lemma setsum_0': "ALL a:F. f a = 0 ==> setsum f F = 0" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
864 |
apply (subgoal_tac "setsum f F = setsum (%x. 0) F") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
865 |
apply (erule ssubst, rule setsum_0) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
866 |
apply (rule setsum_cong, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
867 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
868 |
|
14485 | 869 |
lemma card_eq_setsum: "finite A ==> card A = setsum (%x. 1) A" |
870 |
-- {* Could allow many @{text "card"} proofs to be simplified. *} |
|
871 |
by (induct set: Finites) auto |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
872 |
|
14485 | 873 |
lemma setsum_Un_Int: "finite A ==> finite B |
874 |
==> setsum g (A Un B) + setsum g (A Int B) = setsum g A + setsum g B" |
|
875 |
-- {* The reversed orientation looks more natural, but LOOPS as a simprule! *} |
|
876 |
apply (induct set: Finites, simp) |
|
877 |
apply (simp add: plus_ac0 Int_insert_left insert_absorb) |
|
878 |
done |
|
879 |
||
880 |
lemma setsum_Un_disjoint: "finite A ==> finite B |
|
881 |
==> A Int B = {} ==> setsum g (A Un B) = setsum g A + setsum g B" |
|
882 |
apply (subst setsum_Un_Int [symmetric], auto) |
|
883 |
done |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
884 |
|
14485 | 885 |
lemma setsum_UN_disjoint: |
886 |
"finite I ==> (ALL i:I. finite (A i)) ==> |
|
887 |
(ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==> |
|
888 |
setsum f (UNION I A) = setsum (%i. setsum f (A i)) I" |
|
889 |
apply (induct set: Finites, simp, atomize) |
|
890 |
apply (subgoal_tac "ALL i:F. x \<noteq> i") |
|
891 |
prefer 2 apply blast |
|
892 |
apply (subgoal_tac "A x Int UNION F A = {}") |
|
893 |
prefer 2 apply blast |
|
894 |
apply (simp add: setsum_Un_disjoint) |
|
895 |
done |
|
896 |
||
897 |
lemma setsum_Union_disjoint: |
|
898 |
"finite C ==> (ALL A:C. finite A) ==> |
|
899 |
(ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {}) ==> |
|
900 |
setsum f (Union C) = setsum (setsum f) C" |
|
901 |
apply (frule setsum_UN_disjoint [of C id f]) |
|
902 |
apply (unfold Union_def id_def, assumption+) |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
903 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
904 |
|
14485 | 905 |
lemma setsum_Sigma: "finite A ==> ALL x:A. finite (B x) ==> |
906 |
(\<Sum> x:A. (\<Sum> y:B x. f x y)) = |
|
907 |
(\<Sum> z:(SIGMA x:A. B x). f (fst z) (snd z))" |
|
908 |
apply (subst Sigma_def) |
|
909 |
apply (subst setsum_UN_disjoint) |
|
910 |
apply assumption |
|
911 |
apply (rule ballI) |
|
912 |
apply (drule_tac x = i in bspec, assumption) |
|
913 |
apply (subgoal_tac "(UN y:(B i). {(i, y)}) <= (%y. (i, y)) ` (B i)") |
|
914 |
apply (rule finite_surj) |
|
915 |
apply auto |
|
916 |
apply (rule setsum_cong, rule refl) |
|
917 |
apply (subst setsum_UN_disjoint) |
|
918 |
apply (erule bspec, assumption) |
|
919 |
apply auto |
|
920 |
done |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
921 |
|
14485 | 922 |
lemma setsum_cartesian_product: "finite A ==> finite B ==> |
923 |
(\<Sum> x:A. (\<Sum> y:B. f x y)) = |
|
924 |
(\<Sum> z:A <*> B. f (fst z) (snd z))" |
|
925 |
by (erule setsum_Sigma, auto); |
|
926 |
||
927 |
lemma setsum_addf: "setsum (%x. f x + g x) A = (setsum f A + setsum g A)" |
|
928 |
apply (case_tac "finite A") |
|
929 |
prefer 2 apply (simp add: setsum_def) |
|
930 |
apply (erule finite_induct, auto) |
|
931 |
apply (simp add: plus_ac0) |
|
932 |
done |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
933 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
934 |
subsubsection {* Properties in more restricted classes of structures *} |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
935 |
|
14485 | 936 |
lemma setsum_SucD: "setsum f A = Suc n ==> EX a:A. 0 < f a" |
937 |
apply (case_tac "finite A") |
|
938 |
prefer 2 apply (simp add: setsum_def) |
|
939 |
apply (erule rev_mp) |
|
940 |
apply (erule finite_induct, auto) |
|
941 |
done |
|
942 |
||
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
943 |
lemma setsum_eq_0_iff [simp]: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
944 |
"finite F ==> (setsum f F = 0) = (ALL a:F. f a = (0::nat))" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
945 |
by (induct set: Finites) auto |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
946 |
|
14485 | 947 |
lemma setsum_constant_nat [simp]: |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
948 |
"finite A ==> (\<Sum>x: A. y) = (card A) * y" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
949 |
-- {* Later generalized to any semiring. *} |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
950 |
by (erule finite_induct, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
951 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
952 |
lemma setsum_Un: "finite A ==> finite B ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
953 |
(setsum f (A Un B) :: nat) = setsum f A + setsum f B - setsum f (A Int B)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
954 |
-- {* For the natural numbers, we have subtraction. *} |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
955 |
by (subst setsum_Un_Int [symmetric], auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
956 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
957 |
lemma setsum_Un_ring: "finite A ==> finite B ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
958 |
(setsum f (A Un B) :: 'a :: ring) = |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
959 |
setsum f A + setsum f B - setsum f (A Int B)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
960 |
apply (subst setsum_Un_Int [symmetric], auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
961 |
apply (simp add: compare_rls) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
962 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
963 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
964 |
lemma setsum_diff1: "(setsum f (A - {a}) :: nat) = |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
965 |
(if a:A then setsum f A - f a else setsum f A)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
966 |
apply (case_tac "finite A") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
967 |
prefer 2 apply (simp add: setsum_def) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
968 |
apply (erule finite_induct) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
969 |
apply (auto simp add: insert_Diff_if) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
970 |
apply (drule_tac a = a in mk_disjoint_insert, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
971 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
972 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
973 |
lemma setsum_negf: "finite A ==> setsum (%x. - (f x)::'a::ring) A = |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
974 |
- setsum f A" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
975 |
by (induct set: Finites, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
976 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
977 |
lemma setsum_subtractf: "finite A ==> setsum (%x. ((f x)::'a::ring) - g x) A = |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
978 |
setsum f A - setsum g A" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
979 |
by (simp add: diff_minus setsum_addf setsum_negf) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
980 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
981 |
lemma setsum_nonneg: "[| finite A; |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
982 |
\<forall>x \<in> A. (0::'a::ordered_semiring) \<le> f x |] ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
983 |
0 \<le> setsum f A"; |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
984 |
apply (induct set: Finites, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
985 |
apply (subgoal_tac "0 + 0 \<le> f x + setsum f F", simp) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
986 |
apply (blast intro: add_mono) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
987 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
988 |
|
14485 | 989 |
subsubsection {* Cardinality of unions and Sigma sets *} |
990 |
||
991 |
lemma card_UN_disjoint: |
|
992 |
"finite I ==> (ALL i:I. finite (A i)) ==> |
|
993 |
(ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==> |
|
994 |
card (UNION I A) = setsum (%i. card (A i)) I" |
|
995 |
apply (subst card_eq_setsum) |
|
996 |
apply (subst finite_UN, assumption+) |
|
997 |
apply (subgoal_tac "setsum (%i. card (A i)) I = |
|
998 |
setsum (%i. (setsum (%x. 1) (A i))) I") |
|
999 |
apply (erule ssubst) |
|
1000 |
apply (erule setsum_UN_disjoint, assumption+) |
|
1001 |
apply (rule setsum_cong) |
|
1002 |
apply simp+ |
|
1003 |
done |
|
1004 |
||
1005 |
lemma card_Union_disjoint: |
|
1006 |
"finite C ==> (ALL A:C. finite A) ==> |
|
1007 |
(ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {}) ==> |
|
1008 |
card (Union C) = setsum card C" |
|
1009 |
apply (frule card_UN_disjoint [of C id]) |
|
1010 |
apply (unfold Union_def id_def, assumption+) |
|
1011 |
done |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1012 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1013 |
lemma SigmaI_insert: "y \<notin> A ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1014 |
(SIGMA x:(insert y A). B x) = (({y} <*> (B y)) \<union> (SIGMA x: A. B x))" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1015 |
by auto |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1016 |
|
14485 | 1017 |
lemma card_cartesian_product_singleton: "finite A ==> |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1018 |
card({x} <*> A) = card(A)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1019 |
apply (subgoal_tac "inj_on (%y .(x,y)) A") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1020 |
apply (frule card_image, assumption) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1021 |
apply (subgoal_tac "(Pair x ` A) = {x} <*> A") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1022 |
apply (auto simp add: inj_on_def) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1023 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1024 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1025 |
lemma card_SigmaI [rule_format,simp]: "finite A ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1026 |
(ALL a:A. finite (B a)) --> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1027 |
card (SIGMA x: A. B x) = (\<Sum>a: A. card (B a))" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1028 |
apply (erule finite_induct, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1029 |
apply (subst SigmaI_insert, assumption) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1030 |
apply (subst card_Un_disjoint) |
14485 | 1031 |
apply (auto intro: finite_SigmaI simp add: card_cartesian_product_singleton) |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1032 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1033 |
|
14485 | 1034 |
lemma card_cartesian_product: "[| finite A; finite B |] ==> |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1035 |
card (A <*> B) = card(A) * card(B)" |
14485 | 1036 |
by simp |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1037 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1038 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1039 |
subsection {* Generalized product over a set *} |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1040 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1041 |
constdefs |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1042 |
setprod :: "('a => 'b) => 'a set => 'b::times_ac1" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1043 |
"setprod f A == if finite A then fold (op * o f) 1 A else 1" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1044 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1045 |
syntax |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1046 |
"_setprod" :: "idt => 'a set => 'b => 'b::plus_ac0" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1047 |
("\<Prod>_:_. _" [0, 51, 10] 10) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1048 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1049 |
syntax (xsymbols) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1050 |
"_setprod" :: "idt => 'a set => 'b => 'b::plus_ac0" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1051 |
("\<Prod>_\<in>_. _" [0, 51, 10] 10) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1052 |
translations |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1053 |
"\<Prod>i:A. b" == "setprod (%i. b) A" -- {* Beware of argument permutation! *} |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1054 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1055 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1056 |
lemma setprod_empty [simp]: "setprod f {} = 1" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1057 |
by (auto simp add: setprod_def) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1058 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1059 |
lemma setprod_insert [simp]: "[| finite A; a \<notin> A |] ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1060 |
setprod f (insert a A) = f a * setprod f A" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1061 |
by (auto simp add: setprod_def LC_def LC.fold_insert |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1062 |
times_ac1_left_commute) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1063 |
|
14485 | 1064 |
lemma setprod_reindex [rule_format]: "finite B ==> |
1065 |
inj_on f B --> setprod h (f ` B) = setprod (h \<circ> f) B" |
|
1066 |
apply (rule finite_induct, assumption, force) |
|
1067 |
apply (rule impI, auto) |
|
1068 |
apply (simp add: inj_on_def) |
|
1069 |
apply (subgoal_tac "f x \<notin> f ` F") |
|
1070 |
apply (subgoal_tac "finite (f ` F)") |
|
1071 |
apply (auto simp add: setprod_insert) |
|
1072 |
apply (simp add: inj_on_def) |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1073 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1074 |
|
14485 | 1075 |
lemma setprod_reindex_id: "finite B ==> inj_on f B ==> |
1076 |
setprod f B = setprod id (f ` B)" |
|
1077 |
by (auto simp add: setprod_reindex id_o) |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1078 |
|
14485 | 1079 |
lemma setprod_reindex_cong: "finite A ==> inj_on f A ==> |
1080 |
B = f ` A ==> g = h \<circ> f ==> setprod h B = setprod g A" |
|
1081 |
by (frule setprod_reindex, assumption, simp) |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1082 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1083 |
lemma setprod_cong: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1084 |
"A = B ==> (!!x. x:B ==> f x = g x) ==> setprod f A = setprod g B" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1085 |
apply (case_tac "finite B") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1086 |
prefer 2 apply (simp add: setprod_def, simp) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1087 |
apply (subgoal_tac "ALL C. C <= B --> (ALL x:C. f x = g x) --> setprod f C = setprod g C") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1088 |
apply simp |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1089 |
apply (erule finite_induct, simp) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1090 |
apply (simp add: subset_insert_iff, clarify) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1091 |
apply (subgoal_tac "finite C") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1092 |
prefer 2 apply (blast dest: finite_subset [COMP swap_prems_rl]) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1093 |
apply (subgoal_tac "C = insert x (C - {x})") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1094 |
prefer 2 apply blast |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1095 |
apply (erule ssubst) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1096 |
apply (drule spec) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1097 |
apply (erule (1) notE impE) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1098 |
apply (simp add: Ball_def del:insert_Diff_single) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1099 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1100 |
|
14485 | 1101 |
lemma setprod_1: "setprod (%i. 1) A = 1" |
1102 |
apply (case_tac "finite A") |
|
1103 |
apply (erule finite_induct, auto simp add: times_ac1) |
|
1104 |
apply (simp add: setprod_def) |
|
1105 |
done |
|
1106 |
||
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1107 |
lemma setprod_1': "ALL a:F. f a = 1 ==> setprod f F = 1" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1108 |
apply (subgoal_tac "setprod f F = setprod (%x. 1) F") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1109 |
apply (erule ssubst, rule setprod_1) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1110 |
apply (rule setprod_cong, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1111 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1112 |
|
14485 | 1113 |
lemma setprod_Un_Int: "finite A ==> finite B |
1114 |
==> setprod g (A Un B) * setprod g (A Int B) = setprod g A * setprod g B" |
|
1115 |
apply (induct set: Finites, simp) |
|
1116 |
apply (simp add: times_ac1 insert_absorb) |
|
1117 |
apply (simp add: times_ac1 Int_insert_left insert_absorb) |
|
1118 |
done |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1119 |
|
14485 | 1120 |
lemma setprod_Un_disjoint: "finite A ==> finite B |
1121 |
==> A Int B = {} ==> setprod g (A Un B) = setprod g A * setprod g B" |
|
1122 |
apply (subst setprod_Un_Int [symmetric], auto simp add: times_ac1) |
|
1123 |
done |
|
1124 |
||
1125 |
lemma setprod_UN_disjoint: |
|
1126 |
"finite I ==> (ALL i:I. finite (A i)) ==> |
|
1127 |
(ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==> |
|
1128 |
setprod f (UNION I A) = setprod (%i. setprod f (A i)) I" |
|
1129 |
apply (induct set: Finites, simp, atomize) |
|
1130 |
apply (subgoal_tac "ALL i:F. x \<noteq> i") |
|
1131 |
prefer 2 apply blast |
|
1132 |
apply (subgoal_tac "A x Int UNION F A = {}") |
|
1133 |
prefer 2 apply blast |
|
1134 |
apply (simp add: setprod_Un_disjoint) |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1135 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1136 |
|
14485 | 1137 |
lemma setprod_Union_disjoint: |
1138 |
"finite C ==> (ALL A:C. finite A) ==> |
|
1139 |
(ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {}) ==> |
|
1140 |
setprod f (Union C) = setprod (setprod f) C" |
|
1141 |
apply (frule setprod_UN_disjoint [of C id f]) |
|
1142 |
apply (unfold Union_def id_def, assumption+) |
|
1143 |
done |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1144 |
|
14485 | 1145 |
lemma setprod_Sigma: "finite A ==> ALL x:A. finite (B x) ==> |
1146 |
(\<Prod> x:A. (\<Prod> y: B x. f x y)) = |
|
1147 |
(\<Prod> z:(SIGMA x:A. B x). f (fst z) (snd z))" |
|
1148 |
apply (subst Sigma_def) |
|
1149 |
apply (subst setprod_UN_disjoint) |
|
1150 |
apply assumption |
|
1151 |
apply (rule ballI) |
|
1152 |
apply (drule_tac x = i in bspec, assumption) |
|
1153 |
apply (subgoal_tac "(UN y:(B i). {(i, y)}) <= (%y. (i, y)) ` (B i)") |
|
1154 |
apply (rule finite_surj) |
|
1155 |
apply auto |
|
1156 |
apply (rule setprod_cong, rule refl) |
|
1157 |
apply (subst setprod_UN_disjoint) |
|
1158 |
apply (erule bspec, assumption) |
|
1159 |
apply auto |
|
1160 |
done |
|
1161 |
||
1162 |
lemma setprod_cartesian_product: "finite A ==> finite B ==> |
|
1163 |
(\<Prod> x:A. (\<Prod> y: B. f x y)) = |
|
1164 |
(\<Prod> z:(A <*> B). f (fst z) (snd z))" |
|
1165 |
by (erule setprod_Sigma, auto) |
|
1166 |
||
1167 |
lemma setprod_timesf: "setprod (%x. f x * g x) A = |
|
1168 |
(setprod f A * setprod g A)" |
|
1169 |
apply (case_tac "finite A") |
|
1170 |
prefer 2 apply (simp add: setprod_def times_ac1) |
|
1171 |
apply (erule finite_induct, auto) |
|
1172 |
apply (simp add: times_ac1) |
|
1173 |
done |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1174 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1175 |
subsubsection {* Properties in more restricted classes of structures *} |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1176 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1177 |
lemma setprod_eq_1_iff [simp]: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1178 |
"finite F ==> (setprod f F = 1) = (ALL a:F. f a = (1::nat))" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1179 |
by (induct set: Finites) auto |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1180 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1181 |
lemma setprod_constant: "finite A ==> (\<Prod>x: A. (y::'a::ringpower)) = |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1182 |
y^(card A)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1183 |
apply (erule finite_induct) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1184 |
apply (auto simp add: power_Suc) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1185 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1186 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1187 |
lemma setprod_zero: "finite A ==> EX x: A. f x = (0::'a::semiring) ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1188 |
setprod f A = 0" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1189 |
apply (induct set: Finites, force, clarsimp) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1190 |
apply (erule disjE, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1191 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1192 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1193 |
lemma setprod_nonneg [rule_format]: "(ALL x: A. (0::'a::ordered_ring) \<le> f x) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1194 |
--> 0 \<le> setprod f A" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1195 |
apply (case_tac "finite A") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1196 |
apply (induct set: Finites, force, clarsimp) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1197 |
apply (subgoal_tac "0 * 0 \<le> f x * setprod f F", force) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1198 |
apply (rule mult_mono, assumption+) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1199 |
apply (auto simp add: setprod_def) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1200 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1201 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1202 |
lemma setprod_pos [rule_format]: "(ALL x: A. (0::'a::ordered_ring) < f x) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1203 |
--> 0 < setprod f A" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1204 |
apply (case_tac "finite A") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1205 |
apply (induct set: Finites, force, clarsimp) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1206 |
apply (subgoal_tac "0 * 0 < f x * setprod f F", force) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1207 |
apply (rule mult_strict_mono, assumption+) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1208 |
apply (auto simp add: setprod_def) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1209 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1210 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1211 |
lemma setprod_nonzero [rule_format]: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1212 |
"(ALL x y. (x::'a::semiring) * y = 0 --> x = 0 | y = 0) ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1213 |
finite A ==> (ALL x: A. f x \<noteq> (0::'a)) --> setprod f A \<noteq> 0" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1214 |
apply (erule finite_induct, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1215 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1216 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1217 |
lemma setprod_zero_eq: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1218 |
"(ALL x y. (x::'a::semiring) * y = 0 --> x = 0 | y = 0) ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1219 |
finite A ==> (setprod f A = (0::'a)) = (EX x: A. f x = 0)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1220 |
apply (insert setprod_zero [of A f] setprod_nonzero [of A f], blast) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1221 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1222 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1223 |
lemma setprod_nonzero_field: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1224 |
"finite A ==> (ALL x: A. f x \<noteq> (0::'a::field)) ==> setprod f A \<noteq> 0" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1225 |
apply (rule setprod_nonzero, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1226 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1227 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1228 |
lemma setprod_zero_eq_field: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1229 |
"finite A ==> (setprod f A = (0::'a::field)) = (EX x: A. f x = 0)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1230 |
apply (rule setprod_zero_eq, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1231 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1232 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1233 |
lemma setprod_Un: "finite A ==> finite B ==> (ALL x: A Int B. f x \<noteq> 0) ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1234 |
(setprod f (A Un B) :: 'a ::{field}) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1235 |
= setprod f A * setprod f B / setprod f (A Int B)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1236 |
apply (subst setprod_Un_Int [symmetric], auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1237 |
apply (subgoal_tac "finite (A Int B)") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1238 |
apply (frule setprod_nonzero_field [of "A Int B" f], assumption) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1239 |
apply (subst times_divide_eq_right [THEN sym], auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1240 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1241 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1242 |
lemma setprod_diff1: "finite A ==> f a \<noteq> 0 ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1243 |
(setprod f (A - {a}) :: 'a :: {field}) = |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1244 |
(if a:A then setprod f A / f a else setprod f A)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1245 |
apply (erule finite_induct) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1246 |
apply (auto simp add: insert_Diff_if) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1247 |
apply (subgoal_tac "f a * setprod f F / f a = setprod f F * f a / f a") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1248 |
apply (erule ssubst) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1249 |
apply (subst times_divide_eq_right [THEN sym]) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1250 |
apply (auto simp add: mult_ac) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1251 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1252 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1253 |
lemma setprod_inversef: "finite A ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1254 |
ALL x: A. f x \<noteq> (0::'a::{field,division_by_zero}) ==> |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1255 |
setprod (inverse \<circ> f) A = inverse (setprod f A)" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1256 |
apply (erule finite_induct) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1257 |
apply (simp, simp) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1258 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1259 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1260 |
lemma setprod_dividef: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1261 |
"[|finite A; |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1262 |
\<forall>x \<in> A. g x \<noteq> (0::'a::{field,division_by_zero})|] |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1263 |
==> setprod (%x. f x / g x) A = setprod f A / setprod g A" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1264 |
apply (subgoal_tac |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1265 |
"setprod (%x. f x / g x) A = setprod (%x. f x * (inverse \<circ> g) x) A") |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1266 |
apply (erule ssubst) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1267 |
apply (subst divide_inverse) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1268 |
apply (subst setprod_timesf) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1269 |
apply (subst setprod_inversef, assumption+, rule refl) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1270 |
apply (rule setprod_cong, rule refl) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1271 |
apply (subst divide_inverse, auto) |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1272 |
done |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1273 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1274 |
|
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1275 |
subsection{* Min and Max of finite linearly ordered sets *} |
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1276 |
|
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1277 |
text{* Seemed easier to define directly than via fold. *} |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1278 |
|
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1279 |
lemma ex_Max: fixes S :: "('a::linorder)set" |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1280 |
assumes fin: "finite S" shows "S \<noteq> {} ==> \<exists>m\<in>S. \<forall>s \<in> S. s \<le> m" |
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1281 |
using fin |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1282 |
proof (induct) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1283 |
case empty thus ?case by simp |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1284 |
next |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1285 |
case (insert S x) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1286 |
show ?case |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1287 |
proof (cases) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1288 |
assume "S = {}" thus ?thesis by simp |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1289 |
next |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1290 |
assume nonempty: "S \<noteq> {}" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1291 |
then obtain m where m: "m\<in>S" "\<forall>s\<in>S. s \<le> m" using insert by blast |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1292 |
show ?thesis |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1293 |
proof (cases) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1294 |
assume "x \<le> m" thus ?thesis using m by blast |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1295 |
next |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1296 |
assume "~ x \<le> m" thus ?thesis using m |
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1297 |
by(simp add:linorder_not_le order_less_le)(blast intro: order_trans) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1298 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1299 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1300 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1301 |
|
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1302 |
lemma ex_Min: fixes S :: "('a::linorder)set" |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1303 |
assumes fin: "finite S" shows "S \<noteq> {} ==> \<exists>m\<in>S. \<forall>s \<in> S. m \<le> s" |
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1304 |
using fin |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1305 |
proof (induct) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1306 |
case empty thus ?case by simp |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1307 |
next |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1308 |
case (insert S x) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1309 |
show ?case |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1310 |
proof (cases) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1311 |
assume "S = {}" thus ?thesis by simp |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1312 |
next |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1313 |
assume nonempty: "S \<noteq> {}" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1314 |
then obtain m where m: "m\<in>S" "\<forall>s\<in>S. m \<le> s" using insert by blast |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1315 |
show ?thesis |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1316 |
proof (cases) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1317 |
assume "m \<le> x" thus ?thesis using m by blast |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1318 |
next |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1319 |
assume "~ m \<le> x" thus ?thesis using m |
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1320 |
by(simp add:linorder_not_le order_less_le)(blast intro: order_trans) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1321 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1322 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1323 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1324 |
|
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1325 |
constdefs |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1326 |
Min :: "('a::linorder)set => 'a" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1327 |
"Min S == THE m. m \<in> S \<and> (\<forall>s \<in> S. m \<le> s)" |
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1328 |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1329 |
Max :: "('a::linorder)set => 'a" |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1330 |
"Max S == THE m. m \<in> S \<and> (\<forall>s \<in> S. s \<le> m)" |
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1331 |
|
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1332 |
lemma Min[simp]: assumes a: "finite S" "S \<noteq> {}" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1333 |
shows "Min S \<in> S \<and> (\<forall>s \<in> S. Min S \<le> s)" (is "?P(Min S)") |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1334 |
proof (unfold Min_def, rule theI') |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1335 |
show "\<exists>!m. ?P m" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1336 |
proof (rule ex_ex1I) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1337 |
show "\<exists>m. ?P m" using ex_Min[OF a] by blast |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1338 |
next |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1339 |
fix m1 m2 assume "?P m1" "?P m2" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1340 |
thus "m1 = m2" by (blast dest:order_antisym) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1341 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1342 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1343 |
|
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1344 |
lemma Max[simp]: assumes a: "finite S" "S \<noteq> {}" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1345 |
shows "Max S \<in> S \<and> (\<forall>s \<in> S. s \<le> Max S)" (is "?P(Max S)") |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1346 |
proof (unfold Max_def, rule theI') |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1347 |
show "\<exists>!m. ?P m" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1348 |
proof (rule ex_ex1I) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1349 |
show "\<exists>m. ?P m" using ex_Max[OF a] by blast |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1350 |
next |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1351 |
fix m1 m2 assume "?P m1" "?P m2" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1352 |
thus "m1 = m2" by (blast dest:order_antisym) |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1353 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1354 |
qed |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
13421
diff
changeset
|
1355 |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1356 |
subsection {* Theorems about @{text "choose"} *} |
12396 | 1357 |
|
1358 |
text {* |
|
1359 |
\medskip Basic theorem about @{text "choose"}. By Florian |
|
1360 |
Kammüller, tidied by LCP. |
|
1361 |
*} |
|
1362 |
||
1363 |
lemma card_s_0_eq_empty: |
|
1364 |
"finite A ==> card {B. B \<subseteq> A & card B = 0} = 1" |
|
1365 |
apply (simp cong add: conj_cong add: finite_subset [THEN card_0_eq]) |
|
1366 |
apply (simp cong add: rev_conj_cong) |
|
1367 |
done |
|
1368 |
||
1369 |
lemma choose_deconstruct: "finite M ==> x \<notin> M |
|
1370 |
==> {s. s <= insert x M & card(s) = Suc k} |
|
1371 |
= {s. s <= M & card(s) = Suc k} Un |
|
1372 |
{s. EX t. t <= M & card(t) = k & s = insert x t}" |
|
1373 |
apply safe |
|
1374 |
apply (auto intro: finite_subset [THEN card_insert_disjoint]) |
|
1375 |
apply (drule_tac x = "xa - {x}" in spec) |
|
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1376 |
apply (subgoal_tac "x \<notin> xa", auto) |
12396 | 1377 |
apply (erule rev_mp, subst card_Diff_singleton) |
1378 |
apply (auto intro: finite_subset) |
|
1379 |
done |
|
1380 |
||
1381 |
lemma card_inj_on_le: |
|
13595 | 1382 |
"[|inj_on f A; f ` A \<subseteq> B; finite A; finite B |] ==> card A <= card B" |
12396 | 1383 |
by (auto intro: card_mono simp add: card_image [symmetric]) |
1384 |
||
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1385 |
lemma card_bij_eq: |
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
1386 |
"[|inj_on f A; f ` A \<subseteq> B; inj_on g B; g ` B \<subseteq> A; |
13595 | 1387 |
finite A; finite B |] ==> card A = card B" |
12396 | 1388 |
by (auto intro: le_anti_sym card_inj_on_le) |
1389 |
||
13595 | 1390 |
text{*There are as many subsets of @{term A} having cardinality @{term k} |
1391 |
as there are sets obtained from the former by inserting a fixed element |
|
1392 |
@{term x} into each.*} |
|
1393 |
lemma constr_bij: |
|
1394 |
"[|finite A; x \<notin> A|] ==> |
|
1395 |
card {B. EX C. C <= A & card(C) = k & B = insert x C} = |
|
12396 | 1396 |
card {B. B <= A & card(B) = k}" |
1397 |
apply (rule_tac f = "%s. s - {x}" and g = "insert x" in card_bij_eq) |
|
13595 | 1398 |
apply (auto elim!: equalityE simp add: inj_on_def) |
1399 |
apply (subst Diff_insert0, auto) |
|
1400 |
txt {* finiteness of the two sets *} |
|
1401 |
apply (rule_tac [2] B = "Pow (A)" in finite_subset) |
|
1402 |
apply (rule_tac B = "Pow (insert x A)" in finite_subset) |
|
1403 |
apply fast+ |
|
12396 | 1404 |
done |
1405 |
||
1406 |
text {* |
|
1407 |
Main theorem: combinatorial statement about number of subsets of a set. |
|
1408 |
*} |
|
1409 |
||
1410 |
lemma n_sub_lemma: |
|
1411 |
"!!A. finite A ==> card {B. B <= A & card B = k} = (card A choose k)" |
|
1412 |
apply (induct k) |
|
14208 | 1413 |
apply (simp add: card_s_0_eq_empty, atomize) |
12396 | 1414 |
apply (rotate_tac -1, erule finite_induct) |
13421 | 1415 |
apply (simp_all (no_asm_simp) cong add: conj_cong |
1416 |
add: card_s_0_eq_empty choose_deconstruct) |
|
12396 | 1417 |
apply (subst card_Un_disjoint) |
1418 |
prefer 4 apply (force simp add: constr_bij) |
|
1419 |
prefer 3 apply force |
|
1420 |
prefer 2 apply (blast intro: finite_Pow_iff [THEN iffD2] |
|
1421 |
finite_subset [of _ "Pow (insert x F)", standard]) |
|
1422 |
apply (blast intro: finite_Pow_iff [THEN iffD2, THEN [2] finite_subset]) |
|
1423 |
done |
|
1424 |
||
13421 | 1425 |
theorem n_subsets: |
1426 |
"finite A ==> card {B. B <= A & card B = k} = (card A choose k)" |
|
12396 | 1427 |
by (simp add: n_sub_lemma) |
1428 |
||
14443
75910c7557c5
generic theorems about exponentials; general tidying up
paulson
parents:
14430
diff
changeset
|
1429 |
|
12396 | 1430 |
end |