You are on page 1of 16

Discrete Mathematics

Ch2.2 Set Operations Dr. Talal Bonny


March 13, 2014
1

Set operations: Union


Formal definition for the union of two sets: A U B = { x | x A or x B } Further examples
o {1, 2, 3} U {3, 4, 5} = {1, 2, 3, 4, 5} o {a, b} U {3, 4} = {a, b, 3, 4} o {1, 2} U = {1, 2}

Properties of the union operation


o o o o o AU=A AUU=U AUA=A AUB=BUA A U (B U C) = (A U B) U C Identity law Domination law Idempotent law Commutative law Associative law

Set operations: Intersection


Formal definition for the intersection of two sets: A B = { x | x A and x B } Examples
o {1, 2, 3} {3, 4, 5} = {3} o {a, b} {3, 4} = o {1, 2} =

Properties of the intersection operation


o o o o o AU=A A= AA=A AB=BA A (B C) = (A B) C Identity law Domination law Idempotent law Commutative law Associative law

Disjoint sets
Formal definition for disjoint sets: two sets are disjoint if their intersection is the empty set Further examples
o {1, 2, 3} and {3, 4, 5} are
not disjoint

o {a, b} and {3, 4}


are disjoint

o {1, 2} and
are disjoint Their intersection is the empty set

o and are
disjoint! Their intersection is the empty set

Set operations: Difference


Formal definition for the difference of two sets: A - B = { x | x A and x B }

Further examples
o {1, 2, 3} - {3, 4, 5} =
{1, 2}

o {a, b} - {3, 4} =
{a, b}

o {1, 2} - =
{1, 2} The difference of any set S with the empty set will be the set S

Complement sets
Formal definition for the complement of a set: A = { x | x A } = Ac
o Or U A, where U is the universal set

Further examples (assuming U = Z)


o {1, 2, 3}c =

{ , -2, -1, 0, 4, 5, 6, }

Properties of complement sets


o (Ac)c = A o A U Ac = U o A Ac = Complementation law Complement law Complement law

Set Identities (equivalence)


Set identities is a term used to show equality of two sets. It is similar to the logical equivalences discussed in Section 1.2. The table in the next slide lists the most important set identities. The set identities given can be proved directly from the corresponding logical equivalences.

Set identities
A = A AU = A AA = A AA = A AB = BA AB = BA A(BC) = (AB)C A(BC) = (AB)C A(AB) = A A(AB) = A Identity Law Idempotent Law Commutative Law Associative Law Absorption Law AU = U A = (Ac)c = A (AB)c = AcBc (AB)c = AcBc A(BC) = (AB)(AC) A(BC) = (AB)(AC) A Ac = U A Ac = Domination law Complement Law De Morgans Law

Distributive Law

Complement Law
8

Example
Let A, B, and C be sets. Show that

Solution: We have

Membership Tables
Set identities can also be proved using membership tables. Consider each combination of sets that an element can belong to To indicate that an element is in a set, a 1 is used; To indicate that an element is not in a set, a 0 is used. Notice the similarity between membership tables and truth tables.

10

Membership Tables (cont.)

11

Computer Representation of Sets


One way is to use bitmap First, specify an arbitrary ordering of the elements of U, for instance . Represent a subset A of U with the bit string of length n, where the ith bit in this string is 1 if ai belongs to A and is 0 if ai does not belong to A.

12

Example 1
U is the set of all students in the class. U = {a,b,c,d,e,f,g,h,i,j,k,l,m} We need to represent
o The students who are in the basketball team {c,d,f,k,m}. Basketball team B = {0011010000101} o Honor students who have high CGPA {a,d,j,k,m}. Honor list H = {1001000001101}

Basketball team won the tournament and department is doing a party for which both the basketball players and honor students will be invited o BUH
13

Example 1- contd
{c,d,f,k,m} {a,d,j,k,m} 0011010000101 1001000001101 ------------------1011010001101

What if we only invite those members in the team who are also in the honor list o BH 0011010000101 1001000001101 ------------------0001000000101
14

Example 2

15

Open Book Problem 2


Write a program, in your preferred language, that takes two finite sets and lists all elements in the Cartesian product of these two sets.
o For simplicity, you can assume all elements are integers

16

You might also like