Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Set Operations

Niloufar Shafiei
Set operations
 Two sets can be combined in many
different ways.

 Set operations can be used to combine


sets.

1
Union
Let A and B be sets.

The union of A and B, denoted by AB, is


the set containing those elements that are
either in A or in B, or in both.
U
B A
AB = {x | xA  xB}

2
Union (example)
 {1,2,3}  {2,4,6,8} =
{1,2,3,4,6,8}

 {x| xZ  x is even}  {x|xZ  x is odd} =


Z

3
Intersection
Let A and B be sets.

The intersection of A and B, denoted by A


B, is the set containing those elements in
both A and B.
U
B A
AB = {x | xA  xB}

4
Intersection (example)
 {1,2,3}  {2,4,6,8} =
{2}

 Z  {x|xZ  x is odd} =
{x|xZ  x is odd}

 {x|xZ  x is even}  {x|xZ  x is odd} =


Ø

Two sets are called disjoint if their intersection is empty.


5
The cardinality of the union of sets
|AB|=?

Solution:
A={1,2,3} B={2,3,4} AB={1,2,3,4}
|A|=3 |B|=3 AB|=4

|AB| = |A| + |B| - |AB|


Principle of inclusion-exclusion

6
Difference
Let A and B be sets.

The difference of A and B, denoted by A-B,


is the set containing those elements that
are in A but not in B. (also called complement
of B with respect to A) A B U

A-B = {x | xA  xB}


7
Difference (example)
 {1,2,3} - {2,4} =
{1,3}

 Z - {x|xZ  x is odd} =
{x|xZ  x is even}

8
Complement
Let U be the universal set and A be a set.

The complement of A, denoted by , is the


complement of A with respect to U (which
is U-A).
U
A
 = {x | xA}

9
Complement (example)
 A={a,b,c,d} and U is the set of English
alphabet
 = {e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}

 A = {x|xZ  x is odd} and U is Z


 = {x|xZ  x is even}

10
Set identities
A=A
AU=A Identity laws

AU=U U
A= Domination laws A

AA=A
AA=A
Idempotent laws

() = A Complementation law

A = U
Complement laws
A = 
11
Set identities
AB = BA
AB = BA
Commutative laws U
A B C
A(BC) = (AB)C
A(BC) = (AB)C
Associative laws

A(AB) = A
A(AB) = A
Absorption laws
12
Set identities (example)
Show AB = AB.
Solution:
AB = {x | x  AB }
= {x | ¬(x  AB) }
= {x | ¬((xA)  (xB)) }
= {x | ¬(xA)  ¬(xB) }
= {x | (xA)  (xB) }
= {x | (xA)  (xB) }
= {x | (x  AB)}
= AB
13
Set identities

AB = AB
AB = AB
De Morgan’s laws

There is the similarity between set identities and


logical equivalences.
¬(AB)  ¬A  ¬B
¬(AB)  ¬A  ¬B

14
Set identities (example)
Show A  (B  C) = (A  B)  (A  C).
Solution:
Part 1: A  (B  C)  (A  B)  (A  C)
Assume x  A  (B  C).
(x  A)  (x  (B  C))
(x  A)  (x  B  r x  C)
(x  A  x  B)  (x  A  x  C)
(x  (A  B))  (x  (A  C))
x  (A  B)  (A  C)
So, A  (B  C)  (A  B)  (A  C).
15
Set identities (example)
Show A  (B  C) = (A  B)  (A  C).
Solution:
Part 2: (A  B)  (A  C)  A  (B  C)
Assume x  (A  B)  (A  C).
x  (A  B)  r x  (A  C)
(x  A  x  B)  (x  A  x  C)
x  A  (x  B  x  C)
x  A  (x  (B  C))
x  A  (B  C)
So, (A  B)  (A  C)  A  (B  C) .
Thus, A  (B  C) = (A  B)  (A  C).
16
Set identities
A  (B  C) = (A  B)  (A  C)
A  (B  C) = (A  B)  (A  C)
Distributive laws

There is the similarity between set identities


and logical equivalences.
A(BC)  (AB)  (AC)
A(BC)  (AB)  (AC)

17
Set identities
A  (B  C) = (A  B)  (A  C)
A  (B  C) = (A  B)  (A  C)
Distributive laws
A B C B  C A  (B  C) AB A  C (A  B)  (A  C)
1 1 1 1 1 1 1 1
1 1 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 0 0 0 1 1 1 1
0 1 1 1 1 1 1 1
0 1 0 0 0 1 0 0
0 0 1 0 0 0 1 0
0 0 0 0 0 0 0 0

Membership table 18
Set identities (example)
Show A  (B  C) = (C  B)  A.
Solution:
A  (B  C) =
A  (B  C) = (by De Morgan’s law)
A  (B  C) = (by De Morgan’s law)
(C  B)  A (by commutative law)

19
Database query
The query that returns students that their GPA
is more than B and they are either
computer science or mathematics major.
A: students that their GPA is more than B
B: students that are computer science major.
C: students that are Mathematics major.

A  (BC)
20
Generalized union
Assume A1, A2, … and An are sets

The union of A1, A2, … and An is the set that


contains those elements that are members
of at least one set.
n
A1  A2  …  An =  Ai
i=1

21
Generalized union (example)
n
Assume Ai is {i, i+1, i+2, …}. What is  Ai?
i=1

Solution:
A1 = {1,2,3,…}
A2 = {2,3,4,…}
A3 = {3,4,5,…}
:n
 Ai = {1,2,3,…}
i=1
22
Generalized intersection
Assume A1, A2, … and An are sets

The intersection of A1, A2, … and An is the


set that contains those elements that are
members of all sets.
n
A1  A2  …  An =  Ai
i=1

23
Generalized intersection (example)
n
Assume Ai is {i, i+1, i+2, …}. What is  Ai?
i=1

Solution:
A1 = {1,2,3,…}
A2 = {2,3,4,…}
:
An = {n,n+1,n+2,…}
n
 Ai = {n,n+1,n+2,…}
i=1
24
Generalized union and intersection

A1  A2  …  An  … =  Ai
i=1

A1  A2  …  An  … =  Ai
i=1

25
Example
 
Assume Ai = {1,2,3,…,i}. What is  Ai and  Ai?
i=1 i=1
Solution:
A1 = {1}
A2 = {1,2}
A3 = {1,2,3}
:

 Ai = Z+ 
i=1  Ai = {1}
i=1
26
Recommended exercises
3,5,7,9,11,13,17,19,24,27,29,45,49

27

You might also like