8 |
8 |
9 writeln"File HOL/equalities"; |
9 writeln"File HOL/equalities"; |
10 |
10 |
11 val eq_cs = set_cs addSIs [equalityI]; |
11 val eq_cs = set_cs addSIs [equalityI]; |
12 |
12 |
|
13 goal Set.thy "{x.False} = {}"; |
|
14 by(fast_tac eq_cs 1); |
|
15 qed "Collect_False_empty"; |
|
16 Addsimps [Collect_False_empty]; |
|
17 |
|
18 goal Set.thy "(A <= {}) = (A = {})"; |
|
19 by(fast_tac eq_cs 1); |
|
20 qed "subset_empty"; |
|
21 Addsimps [subset_empty]; |
|
22 |
13 (** The membership relation, : **) |
23 (** The membership relation, : **) |
14 |
24 |
15 goal Set.thy "x ~: {}"; |
25 goal Set.thy "x ~: {}"; |
16 by(fast_tac set_cs 1); |
26 by(fast_tac set_cs 1); |
17 qed "in_empty"; |
27 qed "in_empty"; |
|
28 Addsimps[in_empty]; |
18 |
29 |
19 goal Set.thy "x : insert y A = (x=y | x:A)"; |
30 goal Set.thy "x : insert y A = (x=y | x:A)"; |
20 by(fast_tac set_cs 1); |
31 by(fast_tac set_cs 1); |
21 qed "in_insert"; |
32 qed "in_insert"; |
|
33 Addsimps[in_insert]; |
22 |
34 |
23 (** insert **) |
35 (** insert **) |
|
36 |
|
37 (*NOT SUITABLE FOR REWRITING since {a} == insert a {}*) |
|
38 goal Set.thy "insert a A = {a} Un A"; |
|
39 by(fast_tac eq_cs 1); |
|
40 qed "insert_is_Un"; |
24 |
41 |
25 goal Set.thy "insert a A ~= {}"; |
42 goal Set.thy "insert a A ~= {}"; |
26 by (fast_tac (set_cs addEs [equalityCE]) 1); |
43 by (fast_tac (set_cs addEs [equalityCE]) 1); |
27 qed"insert_not_empty"; |
44 qed"insert_not_empty"; |
|
45 Addsimps[insert_not_empty]; |
28 |
46 |
29 bind_thm("empty_not_insert",insert_not_empty RS not_sym); |
47 bind_thm("empty_not_insert",insert_not_empty RS not_sym); |
|
48 Addsimps[empty_not_insert]; |
30 |
49 |
31 goal Set.thy "!!a. a:A ==> insert a A = A"; |
50 goal Set.thy "!!a. a:A ==> insert a A = A"; |
32 by (fast_tac eq_cs 1); |
51 by (fast_tac eq_cs 1); |
33 qed "insert_absorb"; |
52 qed "insert_absorb"; |
|
53 |
|
54 goal Set.thy "insert x (insert x A) = insert x A"; |
|
55 by(fast_tac eq_cs 1); |
|
56 qed "insert_absorb2"; |
|
57 Addsimps [insert_absorb2]; |
34 |
58 |
35 goal Set.thy "(insert x A <= B) = (x:B & A <= B)"; |
59 goal Set.thy "(insert x A <= B) = (x:B & A <= B)"; |
36 by (fast_tac set_cs 1); |
60 by (fast_tac set_cs 1); |
37 qed "insert_subset"; |
61 qed "insert_subset"; |
|
62 Addsimps[insert_subset]; |
|
63 |
|
64 (* use new B rather than (A-{a}) to avoid infinite unfolding *) |
|
65 goal Set.thy "!!a. a:A ==> ? B. A = insert a B & a ~: B"; |
|
66 by(res_inst_tac [("x","A-{a}")] exI 1); |
|
67 by(fast_tac eq_cs 1); |
|
68 qed "mk_disjoint_insert"; |
38 |
69 |
39 (** Image **) |
70 (** Image **) |
40 |
71 |
41 goal Set.thy "f``{} = {}"; |
72 goal Set.thy "f``{} = {}"; |
42 by (fast_tac eq_cs 1); |
73 by (fast_tac eq_cs 1); |
43 qed "image_empty"; |
74 qed "image_empty"; |
|
75 Addsimps[image_empty]; |
44 |
76 |
45 goal Set.thy "f``insert a B = insert (f a) (f``B)"; |
77 goal Set.thy "f``insert a B = insert (f a) (f``B)"; |
46 by (fast_tac eq_cs 1); |
78 by (fast_tac eq_cs 1); |
47 qed "image_insert"; |
79 qed "image_insert"; |
|
80 Addsimps[image_insert]; |
48 |
81 |
49 (** Binary Intersection **) |
82 (** Binary Intersection **) |
50 |
83 |
51 goal Set.thy "A Int A = A"; |
84 goal Set.thy "A Int A = A"; |
52 by (fast_tac eq_cs 1); |
85 by (fast_tac eq_cs 1); |
53 qed "Int_absorb"; |
86 qed "Int_absorb"; |
|
87 Addsimps[Int_absorb]; |
54 |
88 |
55 goal Set.thy "A Int B = B Int A"; |
89 goal Set.thy "A Int B = B Int A"; |
56 by (fast_tac eq_cs 1); |
90 by (fast_tac eq_cs 1); |
57 qed "Int_commute"; |
91 qed "Int_commute"; |
58 |
92 |
61 qed "Int_assoc"; |
95 qed "Int_assoc"; |
62 |
96 |
63 goal Set.thy "{} Int B = {}"; |
97 goal Set.thy "{} Int B = {}"; |
64 by (fast_tac eq_cs 1); |
98 by (fast_tac eq_cs 1); |
65 qed "Int_empty_left"; |
99 qed "Int_empty_left"; |
|
100 Addsimps[Int_empty_left]; |
66 |
101 |
67 goal Set.thy "A Int {} = {}"; |
102 goal Set.thy "A Int {} = {}"; |
68 by (fast_tac eq_cs 1); |
103 by (fast_tac eq_cs 1); |
69 qed "Int_empty_right"; |
104 qed "Int_empty_right"; |
|
105 Addsimps[Int_empty_right]; |
|
106 |
|
107 goal Set.thy "UNIV Int B = B"; |
|
108 by (fast_tac eq_cs 1); |
|
109 qed "Int_UNIV_left"; |
|
110 Addsimps[Int_UNIV_left]; |
|
111 |
|
112 goal Set.thy "A Int UNIV = A"; |
|
113 by (fast_tac eq_cs 1); |
|
114 qed "Int_UNIV_right"; |
|
115 Addsimps[Int_UNIV_right]; |
70 |
116 |
71 goal Set.thy "A Int (B Un C) = (A Int B) Un (A Int C)"; |
117 goal Set.thy "A Int (B Un C) = (A Int B) Un (A Int C)"; |
72 by (fast_tac eq_cs 1); |
118 by (fast_tac eq_cs 1); |
73 qed "Int_Un_distrib"; |
119 qed "Int_Un_distrib"; |
74 |
120 |
75 goal Set.thy "(A<=B) = (A Int B = A)"; |
121 goal Set.thy "(A<=B) = (A Int B = A)"; |
76 by (fast_tac (eq_cs addSEs [equalityE]) 1); |
122 by (fast_tac (eq_cs addSEs [equalityE]) 1); |
77 qed "subset_Int_eq"; |
123 qed "subset_Int_eq"; |
78 |
124 |
|
125 goal Set.thy "(A Int B = UNIV) = (A = UNIV & B = UNIV)"; |
|
126 by (fast_tac (eq_cs addEs [equalityCE]) 1); |
|
127 qed "Int_UNIV"; |
|
128 Addsimps[Int_UNIV]; |
|
129 |
79 (** Binary Union **) |
130 (** Binary Union **) |
80 |
131 |
81 goal Set.thy "A Un A = A"; |
132 goal Set.thy "A Un A = A"; |
82 by (fast_tac eq_cs 1); |
133 by (fast_tac eq_cs 1); |
83 qed "Un_absorb"; |
134 qed "Un_absorb"; |
|
135 Addsimps[Un_absorb]; |
84 |
136 |
85 goal Set.thy "A Un B = B Un A"; |
137 goal Set.thy "A Un B = B Un A"; |
86 by (fast_tac eq_cs 1); |
138 by (fast_tac eq_cs 1); |
87 qed "Un_commute"; |
139 qed "Un_commute"; |
88 |
140 |
91 qed "Un_assoc"; |
143 qed "Un_assoc"; |
92 |
144 |
93 goal Set.thy "{} Un B = B"; |
145 goal Set.thy "{} Un B = B"; |
94 by(fast_tac eq_cs 1); |
146 by(fast_tac eq_cs 1); |
95 qed "Un_empty_left"; |
147 qed "Un_empty_left"; |
|
148 Addsimps[Un_empty_left]; |
96 |
149 |
97 goal Set.thy "A Un {} = A"; |
150 goal Set.thy "A Un {} = A"; |
98 by(fast_tac eq_cs 1); |
151 by(fast_tac eq_cs 1); |
99 qed "Un_empty_right"; |
152 qed "Un_empty_right"; |
|
153 Addsimps[Un_empty_right]; |
|
154 |
|
155 goal Set.thy "UNIV Un B = UNIV"; |
|
156 by(fast_tac eq_cs 1); |
|
157 qed "Un_UNIV_left"; |
|
158 Addsimps[Un_UNIV_left]; |
|
159 |
|
160 goal Set.thy "A Un UNIV = UNIV"; |
|
161 by(fast_tac eq_cs 1); |
|
162 qed "Un_UNIV_right"; |
|
163 Addsimps[Un_UNIV_right]; |
100 |
164 |
101 goal Set.thy "insert a B Un C = insert a (B Un C)"; |
165 goal Set.thy "insert a B Un C = insert a (B Un C)"; |
102 by(fast_tac eq_cs 1); |
166 by(fast_tac eq_cs 1); |
103 qed "Un_insert_left"; |
167 qed "Un_insert_left"; |
104 |
168 |
120 qed "subset_insert_iff"; |
184 qed "subset_insert_iff"; |
121 |
185 |
122 goal Set.thy "(A Un B = {}) = (A = {} & B = {})"; |
186 goal Set.thy "(A Un B = {}) = (A = {} & B = {})"; |
123 by (fast_tac (eq_cs addEs [equalityCE]) 1); |
187 by (fast_tac (eq_cs addEs [equalityCE]) 1); |
124 qed "Un_empty"; |
188 qed "Un_empty"; |
|
189 Addsimps[Un_empty]; |
125 |
190 |
126 (** Simple properties of Compl -- complement of a set **) |
191 (** Simple properties of Compl -- complement of a set **) |
127 |
192 |
128 goal Set.thy "A Int Compl(A) = {}"; |
193 goal Set.thy "A Int Compl(A) = {}"; |
129 by (fast_tac eq_cs 1); |
194 by (fast_tac eq_cs 1); |
130 qed "Compl_disjoint"; |
195 qed "Compl_disjoint"; |
131 |
196 Addsimps[Compl_disjoint]; |
132 goal Set.thy "A Un Compl(A) = {x.True}"; |
197 |
|
198 goal Set.thy "A Un Compl(A) = UNIV"; |
133 by (fast_tac eq_cs 1); |
199 by (fast_tac eq_cs 1); |
134 qed "Compl_partition"; |
200 qed "Compl_partition"; |
135 |
201 |
136 goal Set.thy "Compl(Compl(A)) = A"; |
202 goal Set.thy "Compl(Compl(A)) = A"; |
137 by (fast_tac eq_cs 1); |
203 by (fast_tac eq_cs 1); |
138 qed "double_complement"; |
204 qed "double_complement"; |
|
205 Addsimps[double_complement]; |
139 |
206 |
140 goal Set.thy "Compl(A Un B) = Compl(A) Int Compl(B)"; |
207 goal Set.thy "Compl(A Un B) = Compl(A) Int Compl(B)"; |
141 by (fast_tac eq_cs 1); |
208 by (fast_tac eq_cs 1); |
142 qed "Compl_Un"; |
209 qed "Compl_Un"; |
143 |
210 |
163 (** Big Union and Intersection **) |
230 (** Big Union and Intersection **) |
164 |
231 |
165 goal Set.thy "Union({}) = {}"; |
232 goal Set.thy "Union({}) = {}"; |
166 by (fast_tac eq_cs 1); |
233 by (fast_tac eq_cs 1); |
167 qed "Union_empty"; |
234 qed "Union_empty"; |
|
235 Addsimps[Union_empty]; |
|
236 |
|
237 goal Set.thy "Union(UNIV) = UNIV"; |
|
238 by (fast_tac eq_cs 1); |
|
239 qed "Union_UNIV"; |
|
240 Addsimps[Union_UNIV]; |
168 |
241 |
169 goal Set.thy "Union(insert a B) = a Un Union(B)"; |
242 goal Set.thy "Union(insert a B) = a Un Union(B)"; |
170 by (fast_tac eq_cs 1); |
243 by (fast_tac eq_cs 1); |
171 qed "Union_insert"; |
244 qed "Union_insert"; |
|
245 Addsimps[Union_insert]; |
172 |
246 |
173 goal Set.thy "Union(A Un B) = Union(A) Un Union(B)"; |
247 goal Set.thy "Union(A Un B) = Union(A) Un Union(B)"; |
174 by (fast_tac eq_cs 1); |
248 by (fast_tac eq_cs 1); |
175 qed "Union_Un_distrib"; |
249 qed "Union_Un_distrib"; |
|
250 Addsimps[Union_Un_distrib]; |
176 |
251 |
177 goal Set.thy "Union(A Int B) <= Union(A) Int Union(B)"; |
252 goal Set.thy "Union(A Int B) <= Union(A) Int Union(B)"; |
178 by (fast_tac set_cs 1); |
253 by (fast_tac set_cs 1); |
179 qed "Union_Int_subset"; |
254 qed "Union_Int_subset"; |
180 |
255 |
181 val prems = goal Set.thy |
256 val prems = goal Set.thy |
182 "(Union(C) Int A = {}) = (! B:C. B Int A = {})"; |
257 "(Union(C) Int A = {}) = (! B:C. B Int A = {})"; |
183 by (fast_tac (eq_cs addSEs [equalityE]) 1); |
258 by (fast_tac (eq_cs addSEs [equalityE]) 1); |
184 qed "Union_disjoint"; |
259 qed "Union_disjoint"; |
185 |
260 |
|
261 goal Set.thy "Inter({}) = UNIV"; |
|
262 by (fast_tac eq_cs 1); |
|
263 qed "Inter_empty"; |
|
264 Addsimps[Inter_empty]; |
|
265 |
|
266 goal Set.thy "Inter(UNIV) = {}"; |
|
267 by (fast_tac eq_cs 1); |
|
268 qed "Inter_UNIV"; |
|
269 Addsimps[Inter_UNIV]; |
|
270 |
|
271 goal Set.thy "Inter(insert a B) = a Int Inter(B)"; |
|
272 by (fast_tac eq_cs 1); |
|
273 qed "Inter_insert"; |
|
274 Addsimps[Inter_insert]; |
|
275 |
|
276 (* Why does fast_tac fail??? |
|
277 goal Set.thy "Inter(A Int B) = Inter(A) Int Inter(B)"; |
|
278 by (fast_tac eq_cs 1); |
|
279 qed "Inter_Int_distrib"; |
|
280 Addsimps[Inter_Int_distrib]; |
|
281 *) |
|
282 |
186 goal Set.thy "Inter(A Un B) = Inter(A) Int Inter(B)"; |
283 goal Set.thy "Inter(A Un B) = Inter(A) Int Inter(B)"; |
187 by (best_tac eq_cs 1); |
284 by (best_tac eq_cs 1); |
188 qed "Inter_Un_distrib"; |
285 qed "Inter_Un_distrib"; |
189 |
286 |
190 (** Unions and Intersections of Families **) |
287 (** Unions and Intersections of Families **) |
192 (*Basic identities*) |
289 (*Basic identities*) |
193 |
290 |
194 goal Set.thy "(UN x:{}. B x) = {}"; |
291 goal Set.thy "(UN x:{}. B x) = {}"; |
195 by (fast_tac eq_cs 1); |
292 by (fast_tac eq_cs 1); |
196 qed "UN_empty"; |
293 qed "UN_empty"; |
|
294 Addsimps[UN_empty]; |
|
295 |
|
296 goal Set.thy "(UN x:UNIV. B x) = (UN x. B x)"; |
|
297 by (fast_tac eq_cs 1); |
|
298 qed "UN_UNIV"; |
|
299 Addsimps[UN_UNIV]; |
|
300 |
|
301 goal Set.thy "(INT x:{}. B x) = UNIV"; |
|
302 by (fast_tac eq_cs 1); |
|
303 qed "INT_empty"; |
|
304 Addsimps[INT_empty]; |
|
305 |
|
306 goal Set.thy "(INT x:UNIV. B x) = (INT x. B x)"; |
|
307 by (fast_tac eq_cs 1); |
|
308 qed "INT_UNIV"; |
|
309 Addsimps[INT_UNIV]; |
197 |
310 |
198 goal Set.thy "(UN x:insert a A. B x) = B a Un UNION A B"; |
311 goal Set.thy "(UN x:insert a A. B x) = B a Un UNION A B"; |
199 by (fast_tac eq_cs 1); |
312 by (fast_tac eq_cs 1); |
200 qed "UN_insert"; |
313 qed "UN_insert"; |
|
314 Addsimps[UN_insert]; |
|
315 |
|
316 goal Set.thy "(INT x:insert a A. B x) = B a Int INTER A B"; |
|
317 by (fast_tac eq_cs 1); |
|
318 qed "INT_insert"; |
|
319 Addsimps[INT_insert]; |
201 |
320 |
202 goal Set.thy "Union(range(f)) = (UN x.f(x))"; |
321 goal Set.thy "Union(range(f)) = (UN x.f(x))"; |
203 by (fast_tac eq_cs 1); |
322 by (fast_tac eq_cs 1); |
204 qed "Union_range_eq"; |
323 qed "Union_range_eq"; |
205 |
324 |
292 (** Simple properties of Diff -- set difference **) |
413 (** Simple properties of Diff -- set difference **) |
293 |
414 |
294 goal Set.thy "A-A = {}"; |
415 goal Set.thy "A-A = {}"; |
295 by (fast_tac eq_cs 1); |
416 by (fast_tac eq_cs 1); |
296 qed "Diff_cancel"; |
417 qed "Diff_cancel"; |
|
418 Addsimps[Diff_cancel]; |
297 |
419 |
298 goal Set.thy "{}-A = {}"; |
420 goal Set.thy "{}-A = {}"; |
299 by (fast_tac eq_cs 1); |
421 by (fast_tac eq_cs 1); |
300 qed "empty_Diff"; |
422 qed "empty_Diff"; |
|
423 Addsimps[empty_Diff]; |
301 |
424 |
302 goal Set.thy "A-{} = A"; |
425 goal Set.thy "A-{} = A"; |
303 by (fast_tac eq_cs 1); |
426 by (fast_tac eq_cs 1); |
304 qed "Diff_empty"; |
427 qed "Diff_empty"; |
|
428 Addsimps[Diff_empty]; |
|
429 |
|
430 goal Set.thy "A-UNIV = {}"; |
|
431 by (fast_tac eq_cs 1); |
|
432 qed "Diff_UNIV"; |
|
433 Addsimps[Diff_UNIV]; |
|
434 |
|
435 goal Set.thy "!!x. x~:A ==> A - insert x B = A-B"; |
|
436 by(fast_tac eq_cs 1); |
|
437 qed "Diff_insert0"; |
|
438 Addsimps [Diff_insert0]; |
305 |
439 |
306 (*NOT SUITABLE FOR REWRITING since {a} == insert a 0*) |
440 (*NOT SUITABLE FOR REWRITING since {a} == insert a 0*) |
307 goal Set.thy "A - insert a B = A - B - {a}"; |
441 goal Set.thy "A - insert a B = A - B - {a}"; |
308 by (fast_tac eq_cs 1); |
442 by (fast_tac eq_cs 1); |
309 qed "Diff_insert"; |
443 qed "Diff_insert"; |
310 |
444 |
311 (*NOT SUITABLE FOR REWRITING since {a} == insert a 0*) |
445 (*NOT SUITABLE FOR REWRITING since {a} == insert a 0*) |
312 goal Set.thy "A - insert a B = A - {a} - B"; |
446 goal Set.thy "A - insert a B = A - {a} - B"; |
313 by (fast_tac eq_cs 1); |
447 by (fast_tac eq_cs 1); |
314 qed "Diff_insert2"; |
448 qed "Diff_insert2"; |
|
449 |
|
450 goal Set.thy "insert x A - B = (if x:B then A-B else insert x (A-B))"; |
|
451 by(simp_tac (!simpset setloop split_tac[expand_if]) 1); |
|
452 by(fast_tac eq_cs 1); |
|
453 qed "insert_Diff_if"; |
|
454 |
|
455 goal Set.thy "!!x. x:B ==> insert x A - B = A-B"; |
|
456 by(fast_tac eq_cs 1); |
|
457 qed "insert_Diff1"; |
|
458 Addsimps [insert_Diff1]; |
315 |
459 |
316 val prems = goal Set.thy "a:A ==> insert a (A-{a}) = A"; |
460 val prems = goal Set.thy "a:A ==> insert a (A-{a}) = A"; |
317 by (fast_tac (eq_cs addSIs prems) 1); |
461 by (fast_tac (eq_cs addSIs prems) 1); |
318 qed "insert_Diff"; |
462 qed "insert_Diff"; |
319 |
463 |
320 goal Set.thy "A Int (B-A) = {}"; |
464 goal Set.thy "A Int (B-A) = {}"; |
321 by (fast_tac eq_cs 1); |
465 by (fast_tac eq_cs 1); |
322 qed "Diff_disjoint"; |
466 qed "Diff_disjoint"; |
|
467 Addsimps[Diff_disjoint]; |
323 |
468 |
324 goal Set.thy "!!A. A<=B ==> A Un (B-A) = B"; |
469 goal Set.thy "!!A. A<=B ==> A Un (B-A) = B"; |
325 by (fast_tac eq_cs 1); |
470 by (fast_tac eq_cs 1); |
326 qed "Diff_partition"; |
471 qed "Diff_partition"; |
327 |
472 |
335 |
480 |
336 goal Set.thy "A - (B Int C) = (A-B) Un (A-C)"; |
481 goal Set.thy "A - (B Int C) = (A-B) Un (A-C)"; |
337 by (fast_tac eq_cs 1); |
482 by (fast_tac eq_cs 1); |
338 qed "Diff_Int"; |
483 qed "Diff_Int"; |
339 |
484 |
340 Addsimps |
485 (* Congruence rule for set comprehension *) |
341 [in_empty,in_insert,insert_subset, |
486 val prems = goal Set.thy |
342 insert_not_empty,empty_not_insert, |
487 "[| !!x. P x = Q x; !!x. Q x ==> f x = g x |] ==> \ |
343 Int_absorb,Int_empty_left,Int_empty_right, |
488 \ {f x |x. P x} = {g x|x. Q x}"; |
344 Un_absorb,Un_empty_left,Un_empty_right,Un_empty, |
489 by(simp_tac (!simpset addsimps prems) 1); |
345 UN_empty, UN_insert, |
490 br set_ext 1; |
346 UN1_constant,image_empty, |
491 br iffI 1; |
347 Compl_disjoint,double_complement, |
492 by(fast_tac (eq_cs addss (!simpset addsimps prems)) 1); |
348 Union_empty,Union_insert,empty_subsetI,subset_refl, |
493 be CollectE 1; |
349 Diff_cancel,empty_Diff,Diff_empty,Diff_disjoint]; |
494 be exE 1; |
|
495 by(Asm_simp_tac 1); |
|
496 be conjE 1; |
|
497 by(rtac exI 1 THEN rtac conjI 1 THEN atac 2); |
|
498 by(asm_simp_tac (!simpset addsimps prems) 1); |
|
499 qed "Collect_cong1"; |
|
500 |
|
501 Addsimps[subset_UNIV, empty_subsetI, subset_refl]; |