Discussion #21 Sets & Set Operations; Tuples & Relations Discussion #21 1 Topics Sets and Set Operations Definitions Operations Set Laws Derivations, Equivalences, Proofs Tuples and Relations pairs & n-tuples Cartesian Product Relations subset of the cross product Tuples Discussion #21 2 Sets Sets are collections The things in a collection are called elements or members Sets have no duplicates. Notation { } Special sets N natural numbers {0, 1, 2, …} (some exclude 0 from this set) Z integers; R reals “set builder” notation Enumerate: {1, 2, 3} Ellipsis: {1, 2, …} or {1, 2, … , 100} Universe: U, universe of discorse Empty set: { } or i.e. set with no elements { x | P(x)} all elements in U that satisfy predicate P { x | x>5 x<10} = {6, 7, 8, 9} when U = N Element of: x A Cardinality |A| or #A both denote the number of elements in A, e.g. |{a,b}| = 2 Discussion #21 3 Set Equality, Subsets, Supersets Set Equality A = B if A and B have the same elements A = B xA xB Subsets B xA xB (subset or equal) A B A B x(xB xA) (proper subset) A Supersets A B if B A A B if B A Discussion #21 4 Proofs about Set Equality and the Empty Set Prove: A = B iff A B B A A=B xA xB definition of set equality (xA xB) (xB xA) P Q (P Q) (Q P) ABBA definition of subset Prove: A (i.e. is a subset of every set.) A x xA definition of subset F xA x is false (for if not there is an element of U T Discussion #21 in the empty set, contrary to the defintion) 5 Set Operations: Intersection Intersection A B {x | xA xB} {1, 2, 3} {2, 3, 4} = {2, 3} A B Prove: A B A By definition, A B A xAB xA 1. xA 2. xAB 3. xA xB 4. xA 5. xA xA 6. F Discussion #21 assume negation of conclusion premise def of 3, simplification 1&4, conjunction 5, contradiction 6 Set Operations: Intersection Intersection A B {x | xA xB} {1, 2, 3} {2, 3, 4} = {2, 3} A B Prove: A B A By definition, A B A xAB xA 1. xA 2. xAB 3. xA xB 4. xA 5. xA xA 6. F Discussion #21 assume negation of conclusion premise A simpler proof. def of 3, simplification 1&4, conjunction 5, contradiction 7 Set Operations: Union Union A B {x | xA xB} {1, 2, 3} {2, 3, 4} = {1, 2, 3, 4} No duplicates! A B Prove: A A B By definition, A AB xA xA xB 1. xA 2. xA xB Discussion #21 premise 1, law of addition 8 Set Operations: Set Difference Difference (minus) A – B {x | xA xB} {1, 2, 3} – {2, 3, 4} = {1} Remove elements of B from A A B Prove: A – B A By definition, A – B A xA–B xA 1. x A – B premise 2. x A x B definition 3. x A simplification Discussion #21 9 Set Operations: Complement Complement ~ A U – A {x | xU xA} ~{1, 2, 3} = {4} if U = {1, 2, 3, 4} A Prove: A ~A = A ~A = A ~A A ~A set equality A ~A T is a subset of every set A ~A identity x A x ~A x def of and x A x U x A x def of ~ Fx comm., contradict., dominat. T Note: Unary operators have precedence over binary operators. Use parentheses for the rest. Possible to define precedence: ~, , , . Discussion #21 10 Basic Set Identities Set Algebra Name A ~A = U A ~A = AU=A A=A Complementation law Exclusion law Identity laws AU=U A= Domination laws AA=A AA=A Idempotent laws Duals: and E Discussion #21 11 Basic Set Identities (continued…) Set Algebra Name ~(~A) = A Double Complement Commutative laws AB=BA AB=BA (A B) C = A (B C) (A B) C = A (B C) Associative laws A (B C) = (A B) (A C) A (B C) = (A B) (A C) ~ (A B) = ~A ~B ~ (A B) = ~A ~B Distributive laws Discussion #21 De Morgan’s laws 12 Example: Set Laws Absorption A (A B) = A A (A B) = A A B Venn Diagram “Proof” Prove: A (A B) = A A (A B) = (A ) (A B) = A ( B) =A =A Discussion #21 ident. distrib. dominat. ident. 13 Tuples Things (usually a small number of things) arranged in order 2-tuples pairs (x, y) ordered (x, y) (y, x) unless x = y n-tuples = (x1, x2, …, xn) Typically, elements in tuples are taken from known sets x females, y males (Mary, Jim) e.g. might mean: Mary and Jim are a married couple x people, y cars (Mary, red sports car17) e.g. might mean: Mary owns red sports car17 x, y, z integers (3, 4, 7) e.g. might mean: 3 + 4 = 7 Discussion #21 14 Cartesian Product A B = {(x, y) | xA yB} e.g. A = {1, 2} B = {a, b, c} A B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)} |A B| = |A| · |B| = 2 · 3 = 6 Discussion #21 15 Cartesian Product (continued…) n-fold Cartesian Product A1 … An = {(x1, …, xn) | xA1 … xnAn} e.g. A = {1, 2} B = {a, b, c} C = {, } A B C = {(1,a,), (1,a,), (1,b,), (1,b,), (1,c,), (1,c,), (2,a,), (2,a,), (2,b,), (2,b,), (2,c,), (2,c,)} Can get large: A = set of students at BYU (30,000) B = set of BYU student addresses (10,000) C = set of BYU student phone#’s (60,000) |A| |B| |C| = 1.8 1013 Discussion #21 16 Relations Relation Subset of the cross product Not necessarily a proper subset R A B or R A B C Examples: A = {1, 2} & B = {a, b, c} R = {(1, a), (2, b), (2, c)} A = {1, 2} & B = {a, b, c} & C = {, } R = {(1, a, ), (2, c, )} Marriage: subset of the cross product of males and females Discussion #21 17