src/HOL/Set.ML
 author paulson Thu Sep 12 10:40:05 1996 +0200 (1996-09-12) changeset 1985 84cf16192e03 parent 1937 e59ff0eb1e91 child 2024 909153d8318f permissions -rw-r--r--
Tidied many proofs, using AddIffs to let equivalences take
the place of separate Intr and Elim rules. Also deleted most named clasets.
 clasohm@1465 ` 1` ```(* Title: HOL/set ``` clasohm@923 ` 2` ``` ID: \$Id\$ ``` clasohm@1465 ` 3` ``` Author: Lawrence C Paulson, Cambridge University Computer Laboratory ``` clasohm@923 ` 4` ``` Copyright 1991 University of Cambridge ``` clasohm@923 ` 5` paulson@1985 ` 6` ```Set theory for higher-order logic. A set is simply a predicate. ``` clasohm@923 ` 7` ```*) ``` clasohm@923 ` 8` clasohm@923 ` 9` ```open Set; ``` clasohm@923 ` 10` nipkow@1548 ` 11` ```section "Relating predicates and sets"; ``` nipkow@1548 ` 12` nipkow@1548 ` 13` ```val [prem] = goal Set.thy "P(a) ==> a : {x.P(x)}"; ``` clasohm@923 ` 14` ```by (rtac (mem_Collect_eq RS ssubst) 1); ``` clasohm@923 ` 15` ```by (rtac prem 1); ``` clasohm@923 ` 16` ```qed "CollectI"; ``` clasohm@923 ` 17` clasohm@923 ` 18` ```val prems = goal Set.thy "[| a : {x.P(x)} |] ==> P(a)"; ``` clasohm@923 ` 19` ```by (resolve_tac (prems RL [mem_Collect_eq RS subst]) 1); ``` clasohm@923 ` 20` ```qed "CollectD"; ``` clasohm@923 ` 21` clasohm@923 ` 22` ```val [prem] = goal Set.thy "[| !!x. (x:A) = (x:B) |] ==> A = B"; ``` clasohm@923 ` 23` ```by (rtac (prem RS ext RS arg_cong RS box_equals) 1); ``` clasohm@923 ` 24` ```by (rtac Collect_mem_eq 1); ``` clasohm@923 ` 25` ```by (rtac Collect_mem_eq 1); ``` clasohm@923 ` 26` ```qed "set_ext"; ``` clasohm@923 ` 27` clasohm@923 ` 28` ```val [prem] = goal Set.thy "[| !!x. P(x)=Q(x) |] ==> {x. P(x)} = {x. Q(x)}"; ``` clasohm@923 ` 29` ```by (rtac (prem RS ext RS arg_cong) 1); ``` clasohm@923 ` 30` ```qed "Collect_cong"; ``` clasohm@923 ` 31` clasohm@923 ` 32` ```val CollectE = make_elim CollectD; ``` clasohm@923 ` 33` nipkow@1548 ` 34` ```section "Bounded quantifiers"; ``` clasohm@923 ` 35` clasohm@923 ` 36` ```val prems = goalw Set.thy [Ball_def] ``` clasohm@923 ` 37` ``` "[| !!x. x:A ==> P(x) |] ==> ! x:A. P(x)"; ``` clasohm@923 ` 38` ```by (REPEAT (ares_tac (prems @ [allI,impI]) 1)); ``` clasohm@923 ` 39` ```qed "ballI"; ``` clasohm@923 ` 40` clasohm@923 ` 41` ```val [major,minor] = goalw Set.thy [Ball_def] ``` clasohm@923 ` 42` ``` "[| ! x:A. P(x); x:A |] ==> P(x)"; ``` clasohm@923 ` 43` ```by (rtac (minor RS (major RS spec RS mp)) 1); ``` clasohm@923 ` 44` ```qed "bspec"; ``` clasohm@923 ` 45` clasohm@923 ` 46` ```val major::prems = goalw Set.thy [Ball_def] ``` clasohm@923 ` 47` ``` "[| ! x:A. P(x); P(x) ==> Q; x~:A ==> Q |] ==> Q"; ``` clasohm@923 ` 48` ```by (rtac (major RS spec RS impCE) 1); ``` clasohm@923 ` 49` ```by (REPEAT (eresolve_tac prems 1)); ``` clasohm@923 ` 50` ```qed "ballE"; ``` clasohm@923 ` 51` clasohm@923 ` 52` ```(*Takes assumptions ! x:A.P(x) and a:A; creates assumption P(a)*) ``` clasohm@923 ` 53` ```fun ball_tac i = etac ballE i THEN contr_tac (i+1); ``` clasohm@923 ` 54` clasohm@923 ` 55` ```val prems = goalw Set.thy [Bex_def] ``` clasohm@923 ` 56` ``` "[| P(x); x:A |] ==> ? x:A. P(x)"; ``` clasohm@923 ` 57` ```by (REPEAT (ares_tac (prems @ [exI,conjI]) 1)); ``` clasohm@923 ` 58` ```qed "bexI"; ``` clasohm@923 ` 59` clasohm@923 ` 60` ```qed_goal "bexCI" Set.thy ``` clasohm@923 ` 61` ``` "[| ! x:A. ~P(x) ==> P(a); a:A |] ==> ? x:A.P(x)" ``` clasohm@923 ` 62` ``` (fn prems=> ``` clasohm@923 ` 63` ``` [ (rtac classical 1), ``` clasohm@923 ` 64` ``` (REPEAT (ares_tac (prems@[bexI,ballI,notI,notE]) 1)) ]); ``` clasohm@923 ` 65` clasohm@923 ` 66` ```val major::prems = goalw Set.thy [Bex_def] ``` clasohm@923 ` 67` ``` "[| ? x:A. P(x); !!x. [| x:A; P(x) |] ==> Q |] ==> Q"; ``` clasohm@923 ` 68` ```by (rtac (major RS exE) 1); ``` clasohm@923 ` 69` ```by (REPEAT (eresolve_tac (prems @ [asm_rl,conjE]) 1)); ``` clasohm@923 ` 70` ```qed "bexE"; ``` clasohm@923 ` 71` clasohm@923 ` 72` ```(*Trival rewrite rule; (! x:A.P)=P holds only if A is nonempty!*) ``` paulson@1882 ` 73` ```goalw Set.thy [Ball_def] "(! x:A. True) = True"; ``` paulson@1882 ` 74` ```by (Simp_tac 1); ``` paulson@1816 ` 75` ```qed "ball_True"; ``` paulson@1816 ` 76` paulson@1882 ` 77` ```(*Dual form for existentials*) ``` paulson@1882 ` 78` ```goalw Set.thy [Bex_def] "(? x:A. False) = False"; ``` paulson@1882 ` 79` ```by (Simp_tac 1); ``` paulson@1882 ` 80` ```qed "bex_False"; ``` paulson@1882 ` 81` paulson@1882 ` 82` ```Addsimps [ball_True, bex_False]; ``` clasohm@923 ` 83` clasohm@923 ` 84` ```(** Congruence rules **) ``` clasohm@923 ` 85` clasohm@923 ` 86` ```val prems = goal Set.thy ``` clasohm@923 ` 87` ``` "[| A=B; !!x. x:B ==> P(x) = Q(x) |] ==> \ ``` clasohm@923 ` 88` ```\ (! x:A. P(x)) = (! x:B. Q(x))"; ``` clasohm@923 ` 89` ```by (resolve_tac (prems RL [ssubst]) 1); ``` clasohm@923 ` 90` ```by (REPEAT (ares_tac [ballI,iffI] 1 ``` clasohm@923 ` 91` ``` ORELSE eresolve_tac ([make_elim bspec, mp] @ (prems RL [iffE])) 1)); ``` clasohm@923 ` 92` ```qed "ball_cong"; ``` clasohm@923 ` 93` clasohm@923 ` 94` ```val prems = goal Set.thy ``` clasohm@923 ` 95` ``` "[| A=B; !!x. x:B ==> P(x) = Q(x) |] ==> \ ``` clasohm@923 ` 96` ```\ (? x:A. P(x)) = (? x:B. Q(x))"; ``` clasohm@923 ` 97` ```by (resolve_tac (prems RL [ssubst]) 1); ``` clasohm@923 ` 98` ```by (REPEAT (etac bexE 1 ``` clasohm@923 ` 99` ``` ORELSE ares_tac ([bexI,iffI] @ (prems RL [iffD1,iffD2])) 1)); ``` clasohm@923 ` 100` ```qed "bex_cong"; ``` clasohm@923 ` 101` nipkow@1548 ` 102` ```section "Subsets"; ``` clasohm@923 ` 103` clasohm@923 ` 104` ```val prems = goalw Set.thy [subset_def] "(!!x.x:A ==> x:B) ==> A <= B"; ``` clasohm@923 ` 105` ```by (REPEAT (ares_tac (prems @ [ballI]) 1)); ``` clasohm@923 ` 106` ```qed "subsetI"; ``` clasohm@923 ` 107` clasohm@923 ` 108` ```(*Rule in Modus Ponens style*) ``` clasohm@923 ` 109` ```val major::prems = goalw Set.thy [subset_def] "[| A <= B; c:A |] ==> c:B"; ``` clasohm@923 ` 110` ```by (rtac (major RS bspec) 1); ``` clasohm@923 ` 111` ```by (resolve_tac prems 1); ``` clasohm@923 ` 112` ```qed "subsetD"; ``` clasohm@923 ` 113` clasohm@923 ` 114` ```(*The same, with reversed premises for use with etac -- cf rev_mp*) ``` clasohm@923 ` 115` ```qed_goal "rev_subsetD" Set.thy "[| c:A; A <= B |] ==> c:B" ``` clasohm@923 ` 116` ``` (fn prems=> [ (REPEAT (resolve_tac (prems@[subsetD]) 1)) ]); ``` clasohm@923 ` 117` paulson@1920 ` 118` ```(*Converts A<=B to x:A ==> x:B*) ``` paulson@1920 ` 119` ```fun impOfSubs th = th RSN (2, rev_subsetD); ``` paulson@1920 ` 120` paulson@1841 ` 121` ```qed_goal "contra_subsetD" Set.thy "!!c. [| A <= B; c ~: B |] ==> c ~: A" ``` paulson@1841 ` 122` ``` (fn prems=> [ (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ]); ``` paulson@1841 ` 123` paulson@1841 ` 124` ```qed_goal "rev_contra_subsetD" Set.thy "!!c. [| c ~: B; A <= B |] ==> c ~: A" ``` paulson@1841 ` 125` ``` (fn prems=> [ (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ]); ``` paulson@1841 ` 126` clasohm@923 ` 127` ```(*Classical elimination rule*) ``` clasohm@923 ` 128` ```val major::prems = goalw Set.thy [subset_def] ``` clasohm@923 ` 129` ``` "[| A <= B; c~:A ==> P; c:B ==> P |] ==> P"; ``` clasohm@923 ` 130` ```by (rtac (major RS ballE) 1); ``` clasohm@923 ` 131` ```by (REPEAT (eresolve_tac prems 1)); ``` clasohm@923 ` 132` ```qed "subsetCE"; ``` clasohm@923 ` 133` clasohm@923 ` 134` ```(*Takes assumptions A<=B; c:A and creates the assumption c:B *) ``` clasohm@923 ` 135` ```fun set_mp_tac i = etac subsetCE i THEN mp_tac i; ``` clasohm@923 ` 136` clasohm@923 ` 137` ```qed_goal "subset_refl" Set.thy "A <= (A::'a set)" ``` clasohm@923 ` 138` ``` (fn _=> [ (REPEAT (ares_tac [subsetI] 1)) ]); ``` clasohm@923 ` 139` clasohm@923 ` 140` ```val prems = goal Set.thy "[| A<=B; B<=C |] ==> A<=(C::'a set)"; ``` clasohm@923 ` 141` ```by (cut_facts_tac prems 1); ``` clasohm@923 ` 142` ```by (REPEAT (ares_tac [subsetI] 1 ORELSE set_mp_tac 1)); ``` clasohm@923 ` 143` ```qed "subset_trans"; ``` clasohm@923 ` 144` clasohm@923 ` 145` nipkow@1548 ` 146` ```section "Equality"; ``` clasohm@923 ` 147` clasohm@923 ` 148` ```(*Anti-symmetry of the subset relation*) ``` clasohm@923 ` 149` ```val prems = goal Set.thy "[| A <= B; B <= A |] ==> A = (B::'a set)"; ``` clasohm@923 ` 150` ```by (rtac (iffI RS set_ext) 1); ``` clasohm@923 ` 151` ```by (REPEAT (ares_tac (prems RL [subsetD]) 1)); ``` clasohm@923 ` 152` ```qed "subset_antisym"; ``` clasohm@923 ` 153` ```val equalityI = subset_antisym; ``` clasohm@923 ` 154` berghofe@1762 ` 155` ```AddSIs [equalityI]; ``` berghofe@1762 ` 156` clasohm@923 ` 157` ```(* Equality rules from ZF set theory -- are they appropriate here? *) ``` clasohm@923 ` 158` ```val prems = goal Set.thy "A = B ==> A<=(B::'a set)"; ``` clasohm@923 ` 159` ```by (resolve_tac (prems RL [subst]) 1); ``` clasohm@923 ` 160` ```by (rtac subset_refl 1); ``` clasohm@923 ` 161` ```qed "equalityD1"; ``` clasohm@923 ` 162` clasohm@923 ` 163` ```val prems = goal Set.thy "A = B ==> B<=(A::'a set)"; ``` clasohm@923 ` 164` ```by (resolve_tac (prems RL [subst]) 1); ``` clasohm@923 ` 165` ```by (rtac subset_refl 1); ``` clasohm@923 ` 166` ```qed "equalityD2"; ``` clasohm@923 ` 167` clasohm@923 ` 168` ```val prems = goal Set.thy ``` clasohm@923 ` 169` ``` "[| A = B; [| A<=B; B<=(A::'a set) |] ==> P |] ==> P"; ``` clasohm@923 ` 170` ```by (resolve_tac prems 1); ``` clasohm@923 ` 171` ```by (REPEAT (resolve_tac (prems RL [equalityD1,equalityD2]) 1)); ``` clasohm@923 ` 172` ```qed "equalityE"; ``` clasohm@923 ` 173` clasohm@923 ` 174` ```val major::prems = goal Set.thy ``` clasohm@923 ` 175` ``` "[| A = B; [| c:A; c:B |] ==> P; [| c~:A; c~:B |] ==> P |] ==> P"; ``` clasohm@923 ` 176` ```by (rtac (major RS equalityE) 1); ``` clasohm@923 ` 177` ```by (REPEAT (contr_tac 1 ORELSE eresolve_tac ([asm_rl,subsetCE]@prems) 1)); ``` clasohm@923 ` 178` ```qed "equalityCE"; ``` clasohm@923 ` 179` clasohm@923 ` 180` ```(*Lemma for creating induction formulae -- for "pattern matching" on p ``` clasohm@923 ` 181` ``` To make the induction hypotheses usable, apply "spec" or "bspec" to ``` clasohm@923 ` 182` ``` put universal quantifiers over the free variables in p. *) ``` clasohm@923 ` 183` ```val prems = goal Set.thy ``` clasohm@923 ` 184` ``` "[| p:A; !!z. z:A ==> p=z --> R |] ==> R"; ``` clasohm@923 ` 185` ```by (rtac mp 1); ``` clasohm@923 ` 186` ```by (REPEAT (resolve_tac (refl::prems) 1)); ``` clasohm@923 ` 187` ```qed "setup_induction"; ``` clasohm@923 ` 188` clasohm@923 ` 189` nipkow@1548 ` 190` ```section "Set complement -- Compl"; ``` clasohm@923 ` 191` clasohm@923 ` 192` ```val prems = goalw Set.thy [Compl_def] ``` clasohm@923 ` 193` ``` "[| c:A ==> False |] ==> c : Compl(A)"; ``` clasohm@923 ` 194` ```by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1)); ``` clasohm@923 ` 195` ```qed "ComplI"; ``` clasohm@923 ` 196` clasohm@923 ` 197` ```(*This form, with negated conclusion, works well with the Classical prover. ``` clasohm@923 ` 198` ``` Negated assumptions behave like formulae on the right side of the notional ``` clasohm@923 ` 199` ``` turnstile...*) ``` clasohm@923 ` 200` ```val major::prems = goalw Set.thy [Compl_def] ``` clasohm@923 ` 201` ``` "[| c : Compl(A) |] ==> c~:A"; ``` clasohm@923 ` 202` ```by (rtac (major RS CollectD) 1); ``` clasohm@923 ` 203` ```qed "ComplD"; ``` clasohm@923 ` 204` clasohm@923 ` 205` ```val ComplE = make_elim ComplD; ``` clasohm@923 ` 206` paulson@1640 ` 207` ```qed_goal "Compl_iff" Set.thy "(c : Compl(A)) = (c~:A)" ``` berghofe@1760 ` 208` ``` (fn _ => [ (fast_tac (!claset addSIs [ComplI] addSEs [ComplE]) 1) ]); ``` paulson@1640 ` 209` clasohm@923 ` 210` nipkow@1548 ` 211` ```section "Binary union -- Un"; ``` clasohm@923 ` 212` clasohm@923 ` 213` ```val prems = goalw Set.thy [Un_def] "c:A ==> c : A Un B"; ``` clasohm@923 ` 214` ```by (REPEAT (resolve_tac (prems @ [CollectI,disjI1]) 1)); ``` clasohm@923 ` 215` ```qed "UnI1"; ``` clasohm@923 ` 216` clasohm@923 ` 217` ```val prems = goalw Set.thy [Un_def] "c:B ==> c : A Un B"; ``` clasohm@923 ` 218` ```by (REPEAT (resolve_tac (prems @ [CollectI,disjI2]) 1)); ``` clasohm@923 ` 219` ```qed "UnI2"; ``` clasohm@923 ` 220` clasohm@923 ` 221` ```(*Classical introduction rule: no commitment to A vs B*) ``` clasohm@923 ` 222` ```qed_goal "UnCI" Set.thy "(c~:B ==> c:A) ==> c : A Un B" ``` clasohm@923 ` 223` ``` (fn prems=> ``` clasohm@923 ` 224` ``` [ (rtac classical 1), ``` clasohm@923 ` 225` ``` (REPEAT (ares_tac (prems@[UnI1,notI]) 1)), ``` clasohm@923 ` 226` ``` (REPEAT (ares_tac (prems@[UnI2,notE]) 1)) ]); ``` clasohm@923 ` 227` clasohm@923 ` 228` ```val major::prems = goalw Set.thy [Un_def] ``` clasohm@923 ` 229` ``` "[| c : A Un B; c:A ==> P; c:B ==> P |] ==> P"; ``` clasohm@923 ` 230` ```by (rtac (major RS CollectD RS disjE) 1); ``` clasohm@923 ` 231` ```by (REPEAT (eresolve_tac prems 1)); ``` clasohm@923 ` 232` ```qed "UnE"; ``` clasohm@923 ` 233` paulson@1640 ` 234` ```qed_goal "Un_iff" Set.thy "(c : A Un B) = (c:A | c:B)" ``` berghofe@1760 ` 235` ``` (fn _ => [ (fast_tac (!claset addSIs [UnCI] addSEs [UnE]) 1) ]); ``` paulson@1640 ` 236` clasohm@923 ` 237` nipkow@1548 ` 238` ```section "Binary intersection -- Int"; ``` clasohm@923 ` 239` clasohm@923 ` 240` ```val prems = goalw Set.thy [Int_def] ``` clasohm@923 ` 241` ``` "[| c:A; c:B |] ==> c : A Int B"; ``` clasohm@923 ` 242` ```by (REPEAT (resolve_tac (prems @ [CollectI,conjI]) 1)); ``` clasohm@923 ` 243` ```qed "IntI"; ``` clasohm@923 ` 244` clasohm@923 ` 245` ```val [major] = goalw Set.thy [Int_def] "c : A Int B ==> c:A"; ``` clasohm@923 ` 246` ```by (rtac (major RS CollectD RS conjunct1) 1); ``` clasohm@923 ` 247` ```qed "IntD1"; ``` clasohm@923 ` 248` clasohm@923 ` 249` ```val [major] = goalw Set.thy [Int_def] "c : A Int B ==> c:B"; ``` clasohm@923 ` 250` ```by (rtac (major RS CollectD RS conjunct2) 1); ``` clasohm@923 ` 251` ```qed "IntD2"; ``` clasohm@923 ` 252` clasohm@923 ` 253` ```val [major,minor] = goal Set.thy ``` clasohm@923 ` 254` ``` "[| c : A Int B; [| c:A; c:B |] ==> P |] ==> P"; ``` clasohm@923 ` 255` ```by (rtac minor 1); ``` clasohm@923 ` 256` ```by (rtac (major RS IntD1) 1); ``` clasohm@923 ` 257` ```by (rtac (major RS IntD2) 1); ``` clasohm@923 ` 258` ```qed "IntE"; ``` clasohm@923 ` 259` paulson@1640 ` 260` ```qed_goal "Int_iff" Set.thy "(c : A Int B) = (c:A & c:B)" ``` berghofe@1760 ` 261` ``` (fn _ => [ (fast_tac (!claset addSIs [IntI] addSEs [IntE]) 1) ]); ``` paulson@1640 ` 262` clasohm@923 ` 263` nipkow@1548 ` 264` ```section "Set difference"; ``` clasohm@923 ` 265` clasohm@923 ` 266` ```qed_goalw "DiffI" Set.thy [set_diff_def] ``` clasohm@923 ` 267` ``` "[| c : A; c ~: B |] ==> c : A - B" ``` clasohm@923 ` 268` ``` (fn prems=> [ (REPEAT (resolve_tac (prems @ [CollectI,conjI]) 1)) ]); ``` clasohm@923 ` 269` clasohm@923 ` 270` ```qed_goalw "DiffD1" Set.thy [set_diff_def] ``` clasohm@923 ` 271` ``` "c : A - B ==> c : A" ``` clasohm@923 ` 272` ``` (fn [major]=> [ (rtac (major RS CollectD RS conjunct1) 1) ]); ``` clasohm@923 ` 273` clasohm@923 ` 274` ```qed_goalw "DiffD2" Set.thy [set_diff_def] ``` clasohm@923 ` 275` ``` "[| c : A - B; c : B |] ==> P" ``` clasohm@923 ` 276` ``` (fn [major,minor]=> ``` clasohm@923 ` 277` ``` [rtac (minor RS (major RS CollectD RS conjunct2 RS notE)) 1]); ``` clasohm@923 ` 278` clasohm@923 ` 279` ```qed_goal "DiffE" Set.thy ``` clasohm@923 ` 280` ``` "[| c : A - B; [| c:A; c~:B |] ==> P |] ==> P" ``` clasohm@923 ` 281` ``` (fn prems=> ``` clasohm@923 ` 282` ``` [ (resolve_tac prems 1), ``` clasohm@923 ` 283` ``` (REPEAT (ares_tac (prems RL [DiffD1, DiffD2 RS notI]) 1)) ]); ``` clasohm@923 ` 284` clasohm@923 ` 285` ```qed_goal "Diff_iff" Set.thy "(c : A-B) = (c:A & c~:B)" ``` berghofe@1760 ` 286` ``` (fn _ => [ (fast_tac (!claset addSIs [DiffI] addSEs [DiffE]) 1) ]); ``` clasohm@923 ` 287` nipkow@1548 ` 288` ```section "The empty set -- {}"; ``` clasohm@923 ` 289` clasohm@923 ` 290` ```qed_goalw "emptyE" Set.thy [empty_def] "a:{} ==> P" ``` clasohm@923 ` 291` ``` (fn [prem] => [rtac (prem RS CollectD RS FalseE) 1]); ``` clasohm@923 ` 292` clasohm@923 ` 293` ```qed_goal "empty_subsetI" Set.thy "{} <= A" ``` clasohm@923 ` 294` ``` (fn _ => [ (REPEAT (ares_tac [equalityI,subsetI,emptyE] 1)) ]); ``` clasohm@923 ` 295` clasohm@923 ` 296` ```qed_goal "equals0I" Set.thy "[| !!y. y:A ==> False |] ==> A={}" ``` clasohm@923 ` 297` ``` (fn prems=> ``` clasohm@923 ` 298` ``` [ (REPEAT (ares_tac (prems@[empty_subsetI,subsetI,equalityI]) 1 ``` clasohm@923 ` 299` ``` ORELSE eresolve_tac (prems RL [FalseE]) 1)) ]); ``` clasohm@923 ` 300` clasohm@923 ` 301` ```qed_goal "equals0D" Set.thy "[| A={}; a:A |] ==> P" ``` clasohm@923 ` 302` ``` (fn [major,minor]=> ``` clasohm@923 ` 303` ``` [ (rtac (minor RS (major RS equalityD1 RS subsetD RS emptyE)) 1) ]); ``` clasohm@923 ` 304` paulson@1640 ` 305` ```qed_goal "empty_iff" Set.thy "(c : {}) = False" ``` berghofe@1760 ` 306` ``` (fn _ => [ (fast_tac (!claset addSEs [emptyE]) 1) ]); ``` paulson@1640 ` 307` paulson@1816 ` 308` ```goal Set.thy "Ball {} P = True"; ``` paulson@1816 ` 309` ```by (simp_tac (HOL_ss addsimps [mem_Collect_eq, Ball_def, empty_def]) 1); ``` paulson@1816 ` 310` ```qed "ball_empty"; ``` paulson@1816 ` 311` paulson@1816 ` 312` ```goal Set.thy "Bex {} P = False"; ``` paulson@1816 ` 313` ```by (simp_tac (HOL_ss addsimps [mem_Collect_eq, Bex_def, empty_def]) 1); ``` paulson@1816 ` 314` ```qed "bex_empty"; ``` paulson@1816 ` 315` ```Addsimps [ball_empty, bex_empty]; ``` paulson@1816 ` 316` clasohm@923 ` 317` nipkow@1548 ` 318` ```section "Augmenting a set -- insert"; ``` clasohm@923 ` 319` clasohm@923 ` 320` ```qed_goalw "insertI1" Set.thy [insert_def] "a : insert a B" ``` clasohm@923 ` 321` ``` (fn _ => [rtac (CollectI RS UnI1) 1, rtac refl 1]); ``` clasohm@923 ` 322` clasohm@923 ` 323` ```qed_goalw "insertI2" Set.thy [insert_def] "a : B ==> a : insert b B" ``` clasohm@923 ` 324` ``` (fn [prem]=> [ (rtac (prem RS UnI2) 1) ]); ``` clasohm@923 ` 325` clasohm@923 ` 326` ```qed_goalw "insertE" Set.thy [insert_def] ``` clasohm@923 ` 327` ``` "[| a : insert b A; a=b ==> P; a:A ==> P |] ==> P" ``` clasohm@923 ` 328` ``` (fn major::prems=> ``` clasohm@923 ` 329` ``` [ (rtac (major RS UnE) 1), ``` clasohm@923 ` 330` ``` (REPEAT (eresolve_tac (prems @ [CollectE]) 1)) ]); ``` clasohm@923 ` 331` clasohm@923 ` 332` ```qed_goal "insert_iff" Set.thy "a : insert b A = (a=b | a:A)" ``` berghofe@1760 ` 333` ``` (fn _ => [fast_tac (!claset addIs [insertI1,insertI2] addSEs [insertE]) 1]); ``` clasohm@923 ` 334` clasohm@923 ` 335` ```(*Classical introduction rule*) ``` clasohm@923 ` 336` ```qed_goal "insertCI" Set.thy "(a~:B ==> a=b) ==> a: insert b B" ``` clasohm@923 ` 337` ``` (fn [prem]=> ``` clasohm@923 ` 338` ``` [ (rtac (disjCI RS (insert_iff RS iffD2)) 1), ``` clasohm@923 ` 339` ``` (etac prem 1) ]); ``` clasohm@923 ` 340` nipkow@1548 ` 341` ```section "Singletons, using insert"; ``` clasohm@923 ` 342` clasohm@923 ` 343` ```qed_goal "singletonI" Set.thy "a : {a}" ``` clasohm@923 ` 344` ``` (fn _=> [ (rtac insertI1 1) ]); ``` clasohm@923 ` 345` clasohm@923 ` 346` ```goalw Set.thy [insert_def] "!!a. b : {a} ==> b=a"; ``` berghofe@1760 ` 347` ```by (fast_tac (!claset addSEs [emptyE,CollectE,UnE]) 1); ``` clasohm@923 ` 348` ```qed "singletonD"; ``` clasohm@923 ` 349` oheimb@1776 ` 350` ```bind_thm ("singletonE", make_elim singletonD); ``` oheimb@1776 ` 351` oheimb@1776 ` 352` ```qed_goal "singleton_iff" thy "(b : {a}) = (b=a)" (fn _ => [ ``` oheimb@1776 ` 353` ``` rtac iffI 1, ``` oheimb@1776 ` 354` ``` etac singletonD 1, ``` oheimb@1776 ` 355` ``` hyp_subst_tac 1, ``` oheimb@1776 ` 356` ``` rtac singletonI 1]); ``` clasohm@923 ` 357` clasohm@923 ` 358` ```val [major] = goal Set.thy "{a}={b} ==> a=b"; ``` clasohm@923 ` 359` ```by (rtac (major RS equalityD1 RS subsetD RS singletonD) 1); ``` clasohm@923 ` 360` ```by (rtac singletonI 1); ``` clasohm@923 ` 361` ```qed "singleton_inject"; ``` clasohm@923 ` 362` nipkow@1531 ` 363` nipkow@1548 ` 364` ```section "The universal set -- UNIV"; ``` nipkow@1531 ` 365` paulson@1882 ` 366` ```qed_goal "UNIV_I" Set.thy "x : UNIV" ``` paulson@1882 ` 367` ``` (fn _ => [rtac ComplI 1, etac emptyE 1]); ``` paulson@1882 ` 368` nipkow@1531 ` 369` ```qed_goal "subset_UNIV" Set.thy "A <= UNIV" ``` paulson@1882 ` 370` ``` (fn _ => [rtac subsetI 1, rtac UNIV_I 1]); ``` nipkow@1531 ` 371` nipkow@1531 ` 372` nipkow@1548 ` 373` ```section "Unions of families -- UNION x:A. B(x) is Union(B``A)"; ``` clasohm@923 ` 374` clasohm@923 ` 375` ```(*The order of the premises presupposes that A is rigid; b may be flexible*) ``` clasohm@923 ` 376` ```val prems = goalw Set.thy [UNION_def] ``` clasohm@923 ` 377` ``` "[| a:A; b: B(a) |] ==> b: (UN x:A. B(x))"; ``` clasohm@923 ` 378` ```by (REPEAT (resolve_tac (prems @ [bexI,CollectI]) 1)); ``` clasohm@923 ` 379` ```qed "UN_I"; ``` clasohm@923 ` 380` clasohm@923 ` 381` ```val major::prems = goalw Set.thy [UNION_def] ``` clasohm@923 ` 382` ``` "[| b : (UN x:A. B(x)); !!x.[| x:A; b: B(x) |] ==> R |] ==> R"; ``` clasohm@923 ` 383` ```by (rtac (major RS CollectD RS bexE) 1); ``` clasohm@923 ` 384` ```by (REPEAT (ares_tac prems 1)); ``` clasohm@923 ` 385` ```qed "UN_E"; ``` clasohm@923 ` 386` clasohm@923 ` 387` ```val prems = goal Set.thy ``` clasohm@923 ` 388` ``` "[| A=B; !!x. x:B ==> C(x) = D(x) |] ==> \ ``` clasohm@923 ` 389` ```\ (UN x:A. C(x)) = (UN x:B. D(x))"; ``` clasohm@923 ` 390` ```by (REPEAT (etac UN_E 1 ``` clasohm@923 ` 391` ``` ORELSE ares_tac ([UN_I,equalityI,subsetI] @ ``` clasohm@1465 ` 392` ``` (prems RL [equalityD1,equalityD2] RL [subsetD])) 1)); ``` clasohm@923 ` 393` ```qed "UN_cong"; ``` clasohm@923 ` 394` clasohm@923 ` 395` nipkow@1548 ` 396` ```section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)"; ``` clasohm@923 ` 397` clasohm@923 ` 398` ```val prems = goalw Set.thy [INTER_def] ``` clasohm@923 ` 399` ``` "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))"; ``` clasohm@923 ` 400` ```by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1)); ``` clasohm@923 ` 401` ```qed "INT_I"; ``` clasohm@923 ` 402` clasohm@923 ` 403` ```val major::prems = goalw Set.thy [INTER_def] ``` clasohm@923 ` 404` ``` "[| b : (INT x:A. B(x)); a:A |] ==> b: B(a)"; ``` clasohm@923 ` 405` ```by (rtac (major RS CollectD RS bspec) 1); ``` clasohm@923 ` 406` ```by (resolve_tac prems 1); ``` clasohm@923 ` 407` ```qed "INT_D"; ``` clasohm@923 ` 408` clasohm@923 ` 409` ```(*"Classical" elimination -- by the Excluded Middle on a:A *) ``` clasohm@923 ` 410` ```val major::prems = goalw Set.thy [INTER_def] ``` clasohm@923 ` 411` ``` "[| b : (INT x:A. B(x)); b: B(a) ==> R; a~:A ==> R |] ==> R"; ``` clasohm@923 ` 412` ```by (rtac (major RS CollectD RS ballE) 1); ``` clasohm@923 ` 413` ```by (REPEAT (eresolve_tac prems 1)); ``` clasohm@923 ` 414` ```qed "INT_E"; ``` clasohm@923 ` 415` clasohm@923 ` 416` ```val prems = goal Set.thy ``` clasohm@923 ` 417` ``` "[| A=B; !!x. x:B ==> C(x) = D(x) |] ==> \ ``` clasohm@923 ` 418` ```\ (INT x:A. C(x)) = (INT x:B. D(x))"; ``` clasohm@923 ` 419` ```by (REPEAT_FIRST (resolve_tac [INT_I,equalityI,subsetI])); ``` clasohm@923 ` 420` ```by (REPEAT (dtac INT_D 1 ``` clasohm@923 ` 421` ``` ORELSE ares_tac (prems RL [equalityD1,equalityD2] RL [subsetD]) 1)); ``` clasohm@923 ` 422` ```qed "INT_cong"; ``` clasohm@923 ` 423` clasohm@923 ` 424` nipkow@1548 ` 425` ```section "Unions over a type; UNION1(B) = Union(range(B))"; ``` clasohm@923 ` 426` clasohm@923 ` 427` ```(*The order of the premises presupposes that A is rigid; b may be flexible*) ``` clasohm@923 ` 428` ```val prems = goalw Set.thy [UNION1_def] ``` clasohm@923 ` 429` ``` "b: B(x) ==> b: (UN x. B(x))"; ``` clasohm@923 ` 430` ```by (REPEAT (resolve_tac (prems @ [TrueI, CollectI RS UN_I]) 1)); ``` clasohm@923 ` 431` ```qed "UN1_I"; ``` clasohm@923 ` 432` clasohm@923 ` 433` ```val major::prems = goalw Set.thy [UNION1_def] ``` clasohm@923 ` 434` ``` "[| b : (UN x. B(x)); !!x. b: B(x) ==> R |] ==> R"; ``` clasohm@923 ` 435` ```by (rtac (major RS UN_E) 1); ``` clasohm@923 ` 436` ```by (REPEAT (ares_tac prems 1)); ``` clasohm@923 ` 437` ```qed "UN1_E"; ``` clasohm@923 ` 438` clasohm@923 ` 439` nipkow@1548 ` 440` ```section "Intersections over a type; INTER1(B) = Inter(range(B))"; ``` clasohm@923 ` 441` clasohm@923 ` 442` ```val prems = goalw Set.thy [INTER1_def] ``` clasohm@923 ` 443` ``` "(!!x. b: B(x)) ==> b : (INT x. B(x))"; ``` clasohm@923 ` 444` ```by (REPEAT (ares_tac (INT_I::prems) 1)); ``` clasohm@923 ` 445` ```qed "INT1_I"; ``` clasohm@923 ` 446` clasohm@923 ` 447` ```val [major] = goalw Set.thy [INTER1_def] ``` clasohm@923 ` 448` ``` "b : (INT x. B(x)) ==> b: B(a)"; ``` clasohm@923 ` 449` ```by (rtac (TrueI RS (CollectI RS (major RS INT_D))) 1); ``` clasohm@923 ` 450` ```qed "INT1_D"; ``` clasohm@923 ` 451` nipkow@1548 ` 452` ```section "Union"; ``` clasohm@923 ` 453` clasohm@923 ` 454` ```(*The order of the premises presupposes that C is rigid; A may be flexible*) ``` clasohm@923 ` 455` ```val prems = goalw Set.thy [Union_def] ``` clasohm@923 ` 456` ``` "[| X:C; A:X |] ==> A : Union(C)"; ``` clasohm@923 ` 457` ```by (REPEAT (resolve_tac (prems @ [UN_I]) 1)); ``` clasohm@923 ` 458` ```qed "UnionI"; ``` clasohm@923 ` 459` clasohm@923 ` 460` ```val major::prems = goalw Set.thy [Union_def] ``` clasohm@923 ` 461` ``` "[| A : Union(C); !!X.[| A:X; X:C |] ==> R |] ==> R"; ``` clasohm@923 ` 462` ```by (rtac (major RS UN_E) 1); ``` clasohm@923 ` 463` ```by (REPEAT (ares_tac prems 1)); ``` clasohm@923 ` 464` ```qed "UnionE"; ``` clasohm@923 ` 465` nipkow@1548 ` 466` ```section "Inter"; ``` clasohm@923 ` 467` clasohm@923 ` 468` ```val prems = goalw Set.thy [Inter_def] ``` clasohm@923 ` 469` ``` "[| !!X. X:C ==> A:X |] ==> A : Inter(C)"; ``` clasohm@923 ` 470` ```by (REPEAT (ares_tac ([INT_I] @ prems) 1)); ``` clasohm@923 ` 471` ```qed "InterI"; ``` clasohm@923 ` 472` clasohm@923 ` 473` ```(*A "destruct" rule -- every X in C contains A as an element, but ``` clasohm@923 ` 474` ``` A:X can hold when X:C does not! This rule is analogous to "spec". *) ``` clasohm@923 ` 475` ```val major::prems = goalw Set.thy [Inter_def] ``` clasohm@923 ` 476` ``` "[| A : Inter(C); X:C |] ==> A:X"; ``` clasohm@923 ` 477` ```by (rtac (major RS INT_D) 1); ``` clasohm@923 ` 478` ```by (resolve_tac prems 1); ``` clasohm@923 ` 479` ```qed "InterD"; ``` clasohm@923 ` 480` clasohm@923 ` 481` ```(*"Classical" elimination rule -- does not require proving X:C *) ``` clasohm@923 ` 482` ```val major::prems = goalw Set.thy [Inter_def] ``` clasohm@923 ` 483` ``` "[| A : Inter(C); A:X ==> R; X~:C ==> R |] ==> R"; ``` clasohm@923 ` 484` ```by (rtac (major RS INT_E) 1); ``` clasohm@923 ` 485` ```by (REPEAT (eresolve_tac prems 1)); ``` clasohm@923 ` 486` ```qed "InterE"; ``` clasohm@923 ` 487` nipkow@1548 ` 488` ```section "The Powerset operator -- Pow"; ``` clasohm@923 ` 489` clasohm@923 ` 490` ```qed_goalw "PowI" Set.thy [Pow_def] "!!A B. A <= B ==> A : Pow(B)" ``` clasohm@923 ` 491` ``` (fn _ => [ (etac CollectI 1) ]); ``` clasohm@923 ` 492` clasohm@923 ` 493` ```qed_goalw "PowD" Set.thy [Pow_def] "!!A B. A : Pow(B) ==> A<=B" ``` clasohm@923 ` 494` ``` (fn _=> [ (etac CollectD 1) ]); ``` clasohm@923 ` 495` clasohm@923 ` 496` ```val Pow_bottom = empty_subsetI RS PowI; (* {}: Pow(B) *) ``` clasohm@923 ` 497` ```val Pow_top = subset_refl RS PowI; (* A : Pow(A) *) ``` oheimb@1776 ` 498` oheimb@1776 ` 499` oheimb@1776 ` 500` oheimb@1776 ` 501` ```(*** Set reasoning tools ***) ``` oheimb@1776 ` 502` oheimb@1776 ` 503` oheimb@1776 ` 504` ```val mem_simps = [ Un_iff, Int_iff, Compl_iff, Diff_iff, singleton_iff, ``` oheimb@1776 ` 505` ``` mem_Collect_eq]; ``` oheimb@1776 ` 506` paulson@1937 ` 507` ```(*Not for Addsimps -- it can cause goals to blow up!*) ``` paulson@1937 ` 508` ```goal Set.thy "(a : (if Q then x else y)) = ((Q --> a:x) & (~Q --> a : y))"; ``` paulson@1937 ` 509` ```by (simp_tac (!simpset setloop split_tac [expand_if]) 1); ``` paulson@1937 ` 510` ```qed "mem_if"; ``` paulson@1937 ` 511` oheimb@1776 ` 512` ```val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs; ``` oheimb@1776 ` 513` oheimb@1776 ` 514` ```simpset := !simpset addsimps mem_simps ``` oheimb@1776 ` 515` ``` addcongs [ball_cong,bex_cong] ``` oheimb@1776 ` 516` ``` setmksimps (mksimps mksimps_pairs); ```