17456

1 
header {* Extending FOL by a modified version of HOL set theory *}


2 


3 
theory Set


4 
imports FOL


5 
begin

0

6 

17456

7 
typedecl 'a set


8 
arities set :: ("term") "term"

0

9 


10 
consts


11 
Collect :: "['a => o] => 'a set" (*comprehension*)


12 
Compl :: "('a set) => 'a set" (*complement*)

24825

13 
Int :: "['a set, 'a set] => 'a set" (infixl "Int" 70)


14 
Un :: "['a set, 'a set] => 'a set" (infixl "Un" 65)

17456

15 
Union :: "(('a set)set) => 'a set" (*...of a set*)


16 
Inter :: "(('a set)set) => 'a set" (*...of a set*)


17 
UNION :: "['a set, 'a => 'b set] => 'b set" (*general*)


18 
INTER :: "['a set, 'a => 'b set] => 'b set" (*general*)


19 
Ball :: "['a set, 'a => o] => o" (*bounded quants*)


20 
Bex :: "['a set, 'a => o] => o" (*bounded quants*)

0

21 
mono :: "['a set => 'b set] => o" (*monotonicity*)

24825

22 
mem :: "['a, 'a set] => o" (infixl ":" 50) (*membership*)


23 
subset :: "['a set, 'a set] => o" (infixl "<=" 50)

0

24 
singleton :: "'a => 'a set" ("{_}")


25 
empty :: "'a set" ("{}")


26 

3935

27 
syntax

35113

28 
"_Coll" :: "[idt, o] => 'a set" ("(1{_./ _})") (*collection*)

0

29 


30 
(* Big Intersection / Union *)


31 

35113

32 
"_INTER" :: "[idt, 'a set, 'b set] => 'b set" ("(INT _:_./ _)" [0, 0, 0] 10)


33 
"_UNION" :: "[idt, 'a set, 'b set] => 'b set" ("(UN _:_./ _)" [0, 0, 0] 10)

0

34 


35 
(* Bounded Quantifiers *)


36 

35113

37 
"_Ball" :: "[idt, 'a set, o] => o" ("(ALL _:_./ _)" [0, 0, 0] 10)


38 
"_Bex" :: "[idt, 'a set, o] => o" ("(EX _:_./ _)" [0, 0, 0] 10)

0

39 


40 
translations

35054

41 
"{x. P}" == "CONST Collect(%x. P)"


42 
"INT x:A. B" == "CONST INTER(A, %x. B)"


43 
"UN x:A. B" == "CONST UNION(A, %x. B)"


44 
"ALL x:A. P" == "CONST Ball(A, %x. P)"


45 
"EX x:A. P" == "CONST Bex(A, %x. P)"

0

46 

17456

47 
axioms


48 
mem_Collect_iff: "(a : {x. P(x)}) <> P(a)"


49 
set_extension: "A=B <> (ALL x. x:A <> x:B)"

0

50 

17456

51 
defs


52 
Ball_def: "Ball(A, P) == ALL x. x:A > P(x)"


53 
Bex_def: "Bex(A, P) == EX x. x:A & P(x)"


54 
mono_def: "mono(f) == (ALL A B. A <= B > f(A) <= f(B))"


55 
subset_def: "A <= B == ALL x:A. x:B"


56 
singleton_def: "{a} == {x. x=a}"


57 
empty_def: "{} == {x. False}"


58 
Un_def: "A Un B == {x. x:A  x:B}"


59 
Int_def: "A Int B == {x. x:A & x:B}"


60 
Compl_def: "Compl(A) == {x. ~x:A}"


61 
INTER_def: "INTER(A, B) == {y. ALL x:A. y: B(x)}"


62 
UNION_def: "UNION(A, B) == {y. EX x:A. y: B(x)}"


63 
Inter_def: "Inter(S) == (INT x:S. x)"


64 
Union_def: "Union(S) == (UN x:S. x)"


65 

20140

66 


67 
lemma CollectI: "[ P(a) ] ==> a : {x. P(x)}"


68 
apply (rule mem_Collect_iff [THEN iffD2])


69 
apply assumption


70 
done


71 


72 
lemma CollectD: "[ a : {x. P(x)} ] ==> P(a)"


73 
apply (erule mem_Collect_iff [THEN iffD1])


74 
done


75 


76 
lemmas CollectE = CollectD [elim_format]


77 


78 
lemma set_ext: "[ !!x. x:A <> x:B ] ==> A = B"


79 
apply (rule set_extension [THEN iffD2])


80 
apply simp


81 
done


82 


83 


84 
subsection {* Bounded quantifiers *}


85 


86 
lemma ballI: "[ !!x. x:A ==> P(x) ] ==> ALL x:A. P(x)"


87 
by (simp add: Ball_def)


88 


89 
lemma bspec: "[ ALL x:A. P(x); x:A ] ==> P(x)"


90 
by (simp add: Ball_def)


91 


92 
lemma ballE: "[ ALL x:A. P(x); P(x) ==> Q; ~ x:A ==> Q ] ==> Q"


93 
unfolding Ball_def by blast


94 


95 
lemma bexI: "[ P(x); x:A ] ==> EX x:A. P(x)"


96 
unfolding Bex_def by blast


97 


98 
lemma bexCI: "[ EX x:A. ~P(x) ==> P(a); a:A ] ==> EX x:A. P(x)"


99 
unfolding Bex_def by blast


100 


101 
lemma bexE: "[ EX x:A. P(x); !!x. [ x:A; P(x) ] ==> Q ] ==> Q"


102 
unfolding Bex_def by blast


103 


104 
(*Trival rewrite rule; (! x:A.P)=P holds only if A is nonempty!*)


105 
lemma ball_rew: "(ALL x:A. True) <> True"


106 
by (blast intro: ballI)


107 


108 


109 
subsection {* Congruence rules *}


110 


111 
lemma ball_cong:


112 
"[ A=A'; !!x. x:A' ==> P(x) <> P'(x) ] ==>


113 
(ALL x:A. P(x)) <> (ALL x:A'. P'(x))"


114 
by (blast intro: ballI elim: ballE)


115 


116 
lemma bex_cong:


117 
"[ A=A'; !!x. x:A' ==> P(x) <> P'(x) ] ==>


118 
(EX x:A. P(x)) <> (EX x:A'. P'(x))"


119 
by (blast intro: bexI elim: bexE)


120 


121 


122 
subsection {* Rules for subsets *}


123 


124 
lemma subsetI: "(!!x. x:A ==> x:B) ==> A <= B"


125 
unfolding subset_def by (blast intro: ballI)


126 


127 
(*Rule in Modus Ponens style*)


128 
lemma subsetD: "[ A <= B; c:A ] ==> c:B"


129 
unfolding subset_def by (blast elim: ballE)


130 


131 
(*Classical elimination rule*)


132 
lemma subsetCE: "[ A <= B; ~(c:A) ==> P; c:B ==> P ] ==> P"


133 
by (blast dest: subsetD)


134 


135 
lemma subset_refl: "A <= A"


136 
by (blast intro: subsetI)


137 


138 
lemma subset_trans: "[ A<=B; B<=C ] ==> A<=C"


139 
by (blast intro: subsetI dest: subsetD)


140 


141 


142 
subsection {* Rules for equality *}


143 


144 
(*Antisymmetry of the subset relation*)


145 
lemma subset_antisym: "[ A <= B; B <= A ] ==> A = B"


146 
by (blast intro: set_ext dest: subsetD)


147 


148 
lemmas equalityI = subset_antisym


149 


150 
(* Equality rules from ZF set theory  are they appropriate here? *)


151 
lemma equalityD1: "A = B ==> A<=B"


152 
and equalityD2: "A = B ==> B<=A"


153 
by (simp_all add: subset_refl)


154 


155 
lemma equalityE: "[ A = B; [ A<=B; B<=A ] ==> P ] ==> P"


156 
by (simp add: subset_refl)


157 


158 
lemma equalityCE:


159 
"[ A = B; [ c:A; c:B ] ==> P; [ ~ c:A; ~ c:B ] ==> P ] ==> P"


160 
by (blast elim: equalityE subsetCE)


161 


162 
lemma trivial_set: "{x. x:A} = A"


163 
by (blast intro: equalityI subsetI CollectI dest: CollectD)


164 


165 


166 
subsection {* Rules for binary union *}


167 


168 
lemma UnI1: "c:A ==> c : A Un B"


169 
and UnI2: "c:B ==> c : A Un B"


170 
unfolding Un_def by (blast intro: CollectI)+


171 


172 
(*Classical introduction rule: no commitment to A vs B*)


173 
lemma UnCI: "(~c:B ==> c:A) ==> c : A Un B"


174 
by (blast intro: UnI1 UnI2)


175 


176 
lemma UnE: "[ c : A Un B; c:A ==> P; c:B ==> P ] ==> P"


177 
unfolding Un_def by (blast dest: CollectD)


178 


179 


180 
subsection {* Rules for small intersection *}


181 


182 
lemma IntI: "[ c:A; c:B ] ==> c : A Int B"


183 
unfolding Int_def by (blast intro: CollectI)


184 


185 
lemma IntD1: "c : A Int B ==> c:A"


186 
and IntD2: "c : A Int B ==> c:B"


187 
unfolding Int_def by (blast dest: CollectD)+


188 


189 
lemma IntE: "[ c : A Int B; [ c:A; c:B ] ==> P ] ==> P"


190 
by (blast dest: IntD1 IntD2)


191 


192 


193 
subsection {* Rules for set complement *}


194 


195 
lemma ComplI: "[ c:A ==> False ] ==> c : Compl(A)"


196 
unfolding Compl_def by (blast intro: CollectI)


197 


198 
(*This form, with negated conclusion, works well with the Classical prover.


199 
Negated assumptions behave like formulae on the right side of the notional


200 
turnstile...*)


201 
lemma ComplD: "[ c : Compl(A) ] ==> ~c:A"


202 
unfolding Compl_def by (blast dest: CollectD)


203 


204 
lemmas ComplE = ComplD [elim_format]


205 


206 


207 
subsection {* Empty sets *}


208 


209 
lemma empty_eq: "{x. False} = {}"


210 
by (simp add: empty_def)


211 


212 
lemma emptyD: "a : {} ==> P"


213 
unfolding empty_def by (blast dest: CollectD)


214 


215 
lemmas emptyE = emptyD [elim_format]


216 


217 
lemma not_emptyD:


218 
assumes "~ A={}"


219 
shows "EX x. x:A"


220 
proof 


221 
have "\<not> (EX x. x:A) \<Longrightarrow> A = {}"


222 
by (rule equalityI) (blast intro!: subsetI elim!: emptyD)+


223 
with prems show ?thesis by blast


224 
qed


225 


226 


227 
subsection {* Singleton sets *}


228 


229 
lemma singletonI: "a : {a}"


230 
unfolding singleton_def by (blast intro: CollectI)


231 


232 
lemma singletonD: "b : {a} ==> b=a"


233 
unfolding singleton_def by (blast dest: CollectD)


234 


235 
lemmas singletonE = singletonD [elim_format]


236 


237 


238 
subsection {* Unions of families *}


239 


240 
(*The order of the premises presupposes that A is rigid; b may be flexible*)


241 
lemma UN_I: "[ a:A; b: B(a) ] ==> b: (UN x:A. B(x))"


242 
unfolding UNION_def by (blast intro: bexI CollectI)


243 


244 
lemma UN_E: "[ b : (UN x:A. B(x)); !!x.[ x:A; b: B(x) ] ==> R ] ==> R"


245 
unfolding UNION_def by (blast dest: CollectD elim: bexE)


246 


247 
lemma UN_cong:


248 
"[ A=B; !!x. x:B ==> C(x) = D(x) ] ==>


249 
(UN x:A. C(x)) = (UN x:B. D(x))"


250 
by (simp add: UNION_def cong: bex_cong)


251 


252 


253 
subsection {* Intersections of families *}


254 


255 
lemma INT_I: "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))"


256 
unfolding INTER_def by (blast intro: CollectI ballI)


257 


258 
lemma INT_D: "[ b : (INT x:A. B(x)); a:A ] ==> b: B(a)"


259 
unfolding INTER_def by (blast dest: CollectD bspec)


260 


261 
(*"Classical" elimination rule  does not require proving X:C *)


262 
lemma INT_E: "[ b : (INT x:A. B(x)); b: B(a) ==> R; ~ a:A ==> R ] ==> R"


263 
unfolding INTER_def by (blast dest: CollectD bspec)


264 


265 
lemma INT_cong:


266 
"[ A=B; !!x. x:B ==> C(x) = D(x) ] ==>


267 
(INT x:A. C(x)) = (INT x:B. D(x))"


268 
by (simp add: INTER_def cong: ball_cong)


269 


270 


271 
subsection {* Rules for Unions *}


272 


273 
(*The order of the premises presupposes that C is rigid; A may be flexible*)


274 
lemma UnionI: "[ X:C; A:X ] ==> A : Union(C)"


275 
unfolding Union_def by (blast intro: UN_I)


276 


277 
lemma UnionE: "[ A : Union(C); !!X.[ A:X; X:C ] ==> R ] ==> R"


278 
unfolding Union_def by (blast elim: UN_E)


279 


280 


281 
subsection {* Rules for Inter *}


282 


283 
lemma InterI: "[ !!X. X:C ==> A:X ] ==> A : Inter(C)"


284 
unfolding Inter_def by (blast intro: INT_I)


285 


286 
(*A "destruct" rule  every X in C contains A as an element, but


287 
A:X can hold when X:C does not! This rule is analogous to "spec". *)


288 
lemma InterD: "[ A : Inter(C); X:C ] ==> A:X"


289 
unfolding Inter_def by (blast dest: INT_D)


290 


291 
(*"Classical" elimination rule  does not require proving X:C *)


292 
lemma InterE: "[ A : Inter(C); A:X ==> R; ~ X:C ==> R ] ==> R"


293 
unfolding Inter_def by (blast elim: INT_E)


294 


295 


296 
section {* Derived rules involving subsets; Union and Intersection as lattice operations *}


297 


298 
subsection {* Big Union  least upper bound of a set *}


299 


300 
lemma Union_upper: "B:A ==> B <= Union(A)"


301 
by (blast intro: subsetI UnionI)


302 


303 
lemma Union_least: "[ !!X. X:A ==> X<=C ] ==> Union(A) <= C"


304 
by (blast intro: subsetI dest: subsetD elim: UnionE)


305 


306 


307 
subsection {* Big Intersection  greatest lower bound of a set *}


308 


309 
lemma Inter_lower: "B:A ==> Inter(A) <= B"


310 
by (blast intro: subsetI dest: InterD)


311 


312 
lemma Inter_greatest: "[ !!X. X:A ==> C<=X ] ==> C <= Inter(A)"


313 
by (blast intro: subsetI InterI dest: subsetD)


314 


315 


316 
subsection {* Finite Union  the least upper bound of 2 sets *}


317 


318 
lemma Un_upper1: "A <= A Un B"


319 
by (blast intro: subsetI UnI1)


320 


321 
lemma Un_upper2: "B <= A Un B"


322 
by (blast intro: subsetI UnI2)


323 


324 
lemma Un_least: "[ A<=C; B<=C ] ==> A Un B <= C"


325 
by (blast intro: subsetI elim: UnE dest: subsetD)


326 


327 


328 
subsection {* Finite Intersection  the greatest lower bound of 2 sets *}


329 


330 
lemma Int_lower1: "A Int B <= A"


331 
by (blast intro: subsetI elim: IntE)


332 


333 
lemma Int_lower2: "A Int B <= B"


334 
by (blast intro: subsetI elim: IntE)


335 


336 
lemma Int_greatest: "[ C<=A; C<=B ] ==> C <= A Int B"


337 
by (blast intro: subsetI IntI dest: subsetD)


338 


339 


340 
subsection {* Monotonicity *}


341 


342 
lemma monoI: "[ !!A B. A <= B ==> f(A) <= f(B) ] ==> mono(f)"


343 
unfolding mono_def by blast


344 


345 
lemma monoD: "[ mono(f); A <= B ] ==> f(A) <= f(B)"


346 
unfolding mono_def by blast


347 


348 
lemma mono_Un: "mono(f) ==> f(A) Un f(B) <= f(A Un B)"


349 
by (blast intro: Un_least dest: monoD intro: Un_upper1 Un_upper2)


350 


351 
lemma mono_Int: "mono(f) ==> f(A Int B) <= f(A) Int f(B)"


352 
by (blast intro: Int_greatest dest: monoD intro: Int_lower1 Int_lower2)


353 


354 


355 
subsection {* Automated reasoning setup *}


356 


357 
lemmas [intro!] = ballI subsetI InterI INT_I CollectI ComplI IntI UnCI singletonI


358 
and [intro] = bexI UnionI UN_I


359 
and [elim!] = bexE UnionE UN_E CollectE ComplE IntE UnE emptyE singletonE


360 
and [elim] = ballE InterD InterE INT_D INT_E subsetD subsetCE


361 


362 
lemma mem_rews:


363 
"(a : A Un B) <> (a:A  a:B)"


364 
"(a : A Int B) <> (a:A & a:B)"


365 
"(a : Compl(B)) <> (~a:B)"


366 
"(a : {b}) <> (a=b)"


367 
"(a : {}) <> False"


368 
"(a : {x. P(x)}) <> P(a)"


369 
by blast+


370 


371 
lemmas [simp] = trivial_set empty_eq mem_rews


372 
and [cong] = ball_cong bex_cong INT_cong UN_cong


373 


374 


375 
section {* Equalities involving union, intersection, inclusion, etc. *}


376 


377 
subsection {* Binary Intersection *}


378 


379 
lemma Int_absorb: "A Int A = A"


380 
by (blast intro: equalityI)


381 


382 
lemma Int_commute: "A Int B = B Int A"


383 
by (blast intro: equalityI)


384 


385 
lemma Int_assoc: "(A Int B) Int C = A Int (B Int C)"


386 
by (blast intro: equalityI)


387 


388 
lemma Int_Un_distrib: "(A Un B) Int C = (A Int C) Un (B Int C)"


389 
by (blast intro: equalityI)


390 


391 
lemma subset_Int_eq: "(A<=B) <> (A Int B = A)"


392 
by (blast intro: equalityI elim: equalityE)


393 


394 


395 
subsection {* Binary Union *}


396 


397 
lemma Un_absorb: "A Un A = A"


398 
by (blast intro: equalityI)


399 


400 
lemma Un_commute: "A Un B = B Un A"


401 
by (blast intro: equalityI)


402 


403 
lemma Un_assoc: "(A Un B) Un C = A Un (B Un C)"


404 
by (blast intro: equalityI)


405 


406 
lemma Un_Int_distrib: "(A Int B) Un C = (A Un C) Int (B Un C)"


407 
by (blast intro: equalityI)


408 


409 
lemma Un_Int_crazy:


410 
"(A Int B) Un (B Int C) Un (C Int A) = (A Un B) Int (B Un C) Int (C Un A)"


411 
by (blast intro: equalityI)


412 


413 
lemma subset_Un_eq: "(A<=B) <> (A Un B = B)"


414 
by (blast intro: equalityI elim: equalityE)


415 


416 


417 
subsection {* Simple properties of @{text "Compl"}  complement of a set *}


418 


419 
lemma Compl_disjoint: "A Int Compl(A) = {x. False}"


420 
by (blast intro: equalityI)


421 


422 
lemma Compl_partition: "A Un Compl(A) = {x. True}"


423 
by (blast intro: equalityI)


424 


425 
lemma double_complement: "Compl(Compl(A)) = A"


426 
by (blast intro: equalityI)


427 


428 
lemma Compl_Un: "Compl(A Un B) = Compl(A) Int Compl(B)"


429 
by (blast intro: equalityI)


430 


431 
lemma Compl_Int: "Compl(A Int B) = Compl(A) Un Compl(B)"


432 
by (blast intro: equalityI)


433 


434 
lemma Compl_UN: "Compl(UN x:A. B(x)) = (INT x:A. Compl(B(x)))"


435 
by (blast intro: equalityI)


436 


437 
lemma Compl_INT: "Compl(INT x:A. B(x)) = (UN x:A. Compl(B(x)))"


438 
by (blast intro: equalityI)


439 


440 
(*Halmos, Naive Set Theory, page 16.*)


441 
lemma Un_Int_assoc_eq: "((A Int B) Un C = A Int (B Un C)) <> (C<=A)"


442 
by (blast intro: equalityI elim: equalityE)


443 


444 


445 
subsection {* Big Union and Intersection *}


446 


447 
lemma Union_Un_distrib: "Union(A Un B) = Union(A) Un Union(B)"


448 
by (blast intro: equalityI)


449 


450 
lemma Union_disjoint:


451 
"(Union(C) Int A = {x. False}) <> (ALL B:C. B Int A = {x. False})"


452 
by (blast intro: equalityI elim: equalityE)


453 


454 
lemma Inter_Un_distrib: "Inter(A Un B) = Inter(A) Int Inter(B)"


455 
by (blast intro: equalityI)


456 


457 


458 
subsection {* Unions and Intersections of Families *}


459 


460 
lemma UN_eq: "(UN x:A. B(x)) = Union({Y. EX x:A. Y=B(x)})"


461 
by (blast intro: equalityI)


462 


463 
(*Look: it has an EXISTENTIAL quantifier*)


464 
lemma INT_eq: "(INT x:A. B(x)) = Inter({Y. EX x:A. Y=B(x)})"


465 
by (blast intro: equalityI)


466 


467 
lemma Int_Union_image: "A Int Union(B) = (UN C:B. A Int C)"


468 
by (blast intro: equalityI)


469 


470 
lemma Un_Inter_image: "A Un Inter(B) = (INT C:B. A Un C)"


471 
by (blast intro: equalityI)


472 


473 


474 
section {* Monotonicity of various operations *}


475 


476 
lemma Union_mono: "A<=B ==> Union(A) <= Union(B)"


477 
by blast


478 


479 
lemma Inter_anti_mono: "[ B<=A ] ==> Inter(A) <= Inter(B)"


480 
by blast


481 


482 
lemma UN_mono:


483 
"[ A<=B; !!x. x:A ==> f(x)<=g(x) ] ==>


484 
(UN x:A. f(x)) <= (UN x:B. g(x))"


485 
by blast


486 


487 
lemma INT_anti_mono:


488 
"[ B<=A; !!x. x:A ==> f(x)<=g(x) ] ==>


489 
(INT x:A. f(x)) <= (INT x:A. g(x))"


490 
by blast


491 


492 
lemma Un_mono: "[ A<=C; B<=D ] ==> A Un B <= C Un D"


493 
by blast


494 


495 
lemma Int_mono: "[ A<=C; B<=D ] ==> A Int B <= C Int D"


496 
by blast


497 


498 
lemma Compl_anti_mono: "[ A<=B ] ==> Compl(B) <= Compl(A)"


499 
by blast

0

500 


501 
end
