Today’s topics Introduction to Set Theory (§1.6)
• Sets • A set is a new type of structure, representing an unordered – Indirect, by cases, and direct collection (group, plurality) of zero or more distinct – Rules of logical inference (different) objects. – Correct & fallacious proofs • Set theory deals with operations between, relations among, and statements about sets. • Reading: Sections 1.6-1.7 • Sets are ubiquitous in computer software systems. • Upcoming • All of mathematics can be defined in terms of some form – Functions of set theory (using predicate logic).
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.1 4.2
Naïve set theory Basic notations for sets
• Basic premise: Any collection or class of objects • For sets, we’ll use variables S, T, U, … (elements) that we can describe (by any means whatsoever) constitutes a set. • We can denote a set S in writing by listing • But, the resulting theory turns out to be logically all of its elements in curly braces: inconsistent! – {a, b, c} is the set of whatever 3 objects are – This means, there exist naïve set theory propositions p such that you can prove that both p and ¬p follow logically from the denoted by a, b, c. axioms of the theory! • Set builder notation: For any proposition – The conjunction of the axioms is a contradiction! – This theory is fundamentally uninteresting, because any possible P(x) over any universe of discourse, statement in it can be (very trivially) “proved” by contradiction! {x|P(x)} is the set of all x such that P(x). • More sophisticated set theories fix this problem.
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.3 4.4 Basic properties of sets Definition of Set Equality
• Sets are inherently unordered: • Two sets are declared to be equal if and only if they contain exactly the same elements. – No matter what objects a, b, and c denote, • In particular, it does not matter how the set is defined or {a, b, c} = {a, c, b} = {b, a, c} = denoted. {b, c, a} = {c, a, b} = {c, b, a}. • For example: The set {1, 2, 3, 4} = • All elements are distinct (unequal); {x | x is an integer where x>0 and x<5 } = multiple listings make no difference! {x | x is a positive integer whose square multiple listings make no difference! is >0 and <25} – If a=b, then {a, b, c} = {a, c} = {b, c} = {a, a, b, a, b, c, c, c, c}. – This set contains (at most) 2 elements! CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.5 4.6
Infinite Sets Venn Diagrams
• Conceptually, sets may be infinite (i.e., not finite, John Venn without end, unending). 1834-1923 • Symbols for some special infinite sets: N = {0, 1, 2, …} The Natural numbers. Z = {…, -2, -1, 0, 1, 2, …} The Zntegers. R = The “Real” numbers, such as 374.1828471929498181917281943125… • “Blackboard Bold” or double-struck font (,,) is also often used for these special number sets. • Infinite sets come in different sizes! More on this after module #4 (functions). CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.7 4.8 Basic Set Relations: Member of The Empty Set
• xS (“x is in S”) is the proposition that • (“null”, “the empty set”) is the unique object x is an lement or member of set S. set that contains no elements whatsoever. – e.g. 3N, “a”{x | x is a letter of the alphabet} • = {} = {x|False} – Can define set equality in terms of relation: • No matter the domain of discourse, S,T: S=T ( x: x S x T) we have the axiom ¬x: x. “Two sets are equal iff they have all the same members.” • xS : ¬(xS) “x is not in S”
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.9 4.10
Subset and Superset Relations Proper (Strict) Subsets & Supersets
• ST (“S is a subset of T”) means that every • ST (“S is a proper subset of T”) means element of S is also an element of T. that ST but T / S . Similar for ST. • ST x (xS xT) Example: • S, SS. {1,2} {1,2,3} • ST (“S is a superset of T”) means TS. S • Note S=T ST ST. T • S / T means ¬(ST), i.e. x(xS xT) Venn Diagram equivalent of ST
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.11 4.12 Sets Are Objects, Too! Cardinality and Finiteness
• The objects that are elements of a set may • |S| (read “the cardinality of S”) is a measure themselves be sets. of how many different elements S has. • E.g. let S={x | x {1,2,3}} • E.g., ||=0, |{1,2,3}| = 3, |{a,b}| = 2, then S={, |{{1,2,3},{4,5}}| = ____ {1}, {2}, {3}, • If |S|N, then we say S is finite. {1,2}, {1,3}, {2,3}, Otherwise, we say S is infinite. {1,2,3}} {1,2,3}} • What are some infinite sets we’ve seen? • Note that 1 {1} {{1}} !!!!
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.13 4.14
The Power Set Operation Review: Set Notations So Far
• The power set P(S) of a set S is the set of • Variable objects x, y, z; sets S, T, U. all subsets of S. P(S) : {x | xS}. • Literal set {a, b, c} and set-builder {x|P(x)}. • E.g. P({a,b}) = {, {a}, {b}, {a,b}}. • relational operator, and the empty set . S • Sometimes P(S) is written 2S. • Set relations =, , , , , , etc. Note that for finite S, |P(S)| = 2|S|. Note that for finite S, |P(S)| = 2 . • Venn diagrams. • It turns out S:|P(S)|>|S|, e.g. |P(N)| > |N|. • Cardinality |S| and infinite sets N, Z, R. There are different sizes of infinite sets! • Power sets P(S).
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.15 4.16 Naïve Set Theory is Inconsistent Ordered n-tuples
• There are some naïve set descriptions that lead to pathological structures that are not well-defined. • These are like sets, except that duplicates – (That do not have self-consistent properties.) matter, and the order makes a difference. • These “sets” mathematically cannot exist. • For nN, an ordered n-tuple or a sequence • E.g. let S = {x | x x }. Is S S? • E.g. let S = {x | xx }. Is SS? or list of length n is written (a , a , …, a ). • Therefore, consistent set theories must restrict the 1 2 n language that can be used to describe sets. Its first element is a1, etc. Contrast with • For purposes of this class, don’t worry about it! • Note that (1, 2) (2, 1) (2, 1, 1). sets’ {} • Empty sequence, singlets, pairs, triples,
Bertrand Russell quadruples, quintuples, …, n-tuples. 1872-1970 CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.17 4.18
Cartesian Products of Sets Review of §1.6
• For sets A, B, their Cartesian product • Sets S, T, U… Special sets N, Z, R. AB : {(a, b) | aA bB }. • Set notations {a,b,...}, {x|P(x)}… • E.g. {a,b}{1,2} = {(a,1),(a,2),(b,1),(b,2)} • Set relation operators xS, S T, ST, S=T, • Note that for finite A, B, |AB|=|A||B|. ST, ST. (These form propositions.) • Note that the Cartesian product is not • Finite vs. infinite sets. commutative: i.e., ¬AB: AB=BA. • Set operations |S|, P(S), ST. • Extends to A1 A2 … An... • Next up: §1.5: More set ops: , , .
René Descartes CompSci 102 © Michael Frank CompSci 102 © Michael Frank (1596-1650)4.19 4.20 Start §1.7: The Union Operator Union Examples
• For sets A, B, theirnion AB is the set • {a,b,c}{2,3} = {a,b,c,2,3} containing all elements that are either in A, • {2,3,5}{3,5,7} = {2,3,5,3,5,7} ={2,3,5,7} or (“”) in B (or, of course, in both). Think “The United • Formally, A,B: AB = {x | xA xB}. States of America • Note that AB is a superset of both A and includes every person who worked B (in fact, it is the smallest such superset): in any U.S. state A, B: (AB A) (AB B) last year.” (This is how the IRS sees it...)
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.21 4.22
The Intersection Operator Intersection Examples
• For sets A, B, their intersection AB is the • {a,b,c}{2,3} = ___ set containing all elements that are • {2,4,6}{3,4,5} = ______{4} simultaneously in A and (“”) in B. Think “The • Formally, A,B: AB={x | xA xB}. intersection of • Note that AB is a subset of both A and B University Ave. and W 13th St. is just (in fact it is the largest such subset): that part of the road A, B: (AB A) (AB B) surface that lies on both streets.”
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.23 4.24 Disjointedness Inclusion-Exclusion Principle
Help, I’ve • Two sets A, B are called been • How many elements are in AB? disjointed! disjoint (i.e., unjoined) |AB| = |A| + |B| |AB| iff their intersection is • Example: How many students are on our empty. (AB=) class email list? Consider set E = I M, • Example: the set of even I = {s | s turned in an information sheet} integers is disjoint with M = {s | s sent the TAs their email address} the set of odd integers. • Some students did both! |E| = |IM| = |I| + |M| |IM|
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.25 4.26
Set Difference Set Difference Examples
• For sets A, B, the difference of A and B, • {1,2,3,4,5,6} {2,3,5,7,9,11} = written AB, is the set of all elements that ______{1,4,6} are in A but not B. Formally: • Z N = {… , 1, 0, 1, 2, … } {0, 1, … } A B : {x | xA xB} = {x | x is an integer but not a nat. #} = {x | ¬(xA xB) } = {x | x is a negative integer} • Also called: = {… , 3, 2, 1} The complement of B with respect to A.
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.27 4.28 Set Difference - Venn Diagram Set Complements
• AB is what’s left after B • The universe of discourse can itself be “takes a bite out of A” considered a set, call it U. Chomp! • When the context clearly defines U, we say Set that for any set AU, the complement of A, AB written A , is the complement of A w.r.t. U, i.e., it is UA. Set A Set B • E.g., If U=N, {3,5} = {0,1,2,4,6,7,...}
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.29 4.30
More on Set Complements Set Identities
• An equivalent definition, when U is clear: • Identity: A = A = AU A = {x | x A} • Domination: AU = U , A = • Idempotent: AA = A = AA A • Double complement: (A) = A A • Commutative: AB = BA , AB = BA • Associative: A(BC)=(AB)C , U A(BC)=(AB)C
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.31 4.32 DeMorgan’s Law for Sets Proving Set Identities
• Exactly analogous to (and provable from) To prove statements about sets, of the form
DeMorgan’s Law for propositions. E1 = E2 (where the Es are set expressions), here are three useful techniques: 1. Prove E E and E E separately. A B = A B 1. Prove E1 E2 and E2 E1 separately. 2. Use set builder notation & A B = A B logical equivalences. 3. Use a membership table.
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.33 4.34
Method 1: Mutual subsets Method 3: Membership Tables
Example: Show A(BC)=(AB)(AC). • Just like truth tables for propositional logic. • Part 1: Show A(BC)(AB)(AC). – Assume xA(BC), & show x(AB)(AC). • Columns for different set expressions. – We know that xA, and either xB or xC. • Rows for all combinations of memberships • Case 1: xB. Then xAB, so x(AB)(AC). • Case 2: xC. Then xAC , so x(AB)(AC). in constituent sets. – Therefore, x(AB)(AC). • Use “1” to indicate membership in the – Therefore, A(BC)(AB)(AC). derived set, “0” for non-membership. • Part 2: Show (AB)(AC) A(BC). … • Prove equivalence with identical columns.
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.35 4.36 Membership Table Example Membership Table Exercise
Prove (AB)B = AB. Prove (AB)C = (AC)(BC). ABC AB (AB)C AC BC (AC)(BC) A B A B (A B ) B A B 000 001 00000 010 01100 011 100 10111 101 110 11100 111
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.37 4.38
Review of §1.6-1.7 Generalized Unions & Intersections
• Sets S, T, U… Special sets N, Z, R. • Since union & intersection are • Set notations {a,b,...}, {x|P(x)}… commutative and associative, we can extend them from operating on ordered • Relations xS, S T, ST, S=T, ST, ST. extend them from operating on ordered pairs of sets (A,B) to operating on • Operations |S|, P(S), , , , , S sequences of sets (A1,…,An), or even on • Set equality proof techniques: unordered sets of sets, – Mutual subsets. X={A | P(A)}. – Derivation using logical equivalences.
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.39 4.40 Generalized Union Generalized Intersection
• Binary union operator: AB • Binary intersection operator: AB • n-ary union: • n-ary intersection: A1A2…An((…((A1A2)…)An) AA2…An : ((…((A1 A2) …) An) 1 2 n 1 (grouping & order is irrelevant) (grouping & order is irrelevant) n • “Big Arch” notation: n • “Big U” notation: A A U i I i i=1 • Or for infinite sets of sets:i=1 • Or for infinite sets of sets: A A AUX AIX
CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.41 4.42
Representations Representing Sets with Bit Strings
• A frequent theme of this course will be For an enumerable u.d. U with ordering methods of representing one discrete methods of representing one discrete x1, x2, …, represent a finite set SU as the structure using another discrete structure of finite bit string B=b b …b where a different type. 1 2 n i: xiS (i CompSci 102 © Michael Frank CompSci 102 © Michael Frank 4.43 4.44