Set Operations - York University · Set operations Two sets can be combined in many different ways....

Post on 01-Jun-2020

5 views 0 download

Transcript of Set Operations - York University · Set operations Two sets can be combined in many different ways....

Set Operations

Niloufar Shafiei

1

Set operations

Two sets can be combined in many

different ways.

Set operations can be used to combine

sets.

2

Union

Let A and B be sets.

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

the set containing those elements that are

either in A or in B, or in both.

A B = {x | x A x B}

UB A

3

Union (example)

{1,2,3} {2,4,6,8} =

{1,2,3,4,6,8}

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

Z

4

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.

A B = {x | x A x B}

UB A

5

Intersection (example)

{1,2,3} {2,4,6,8} =

{2}

Z {x|x Z x is odd} =

{x|x Z x is odd}

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

Ø

Two sets are called disjoint if their intersection is empty.

6

The cardinality of the union of sets

|A B|=?

Solution:

A={1,2,3} B={2,3,4} A B={1,2,3,4}

|A|=3 |B|=3 A B|=4

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

Principle of inclusion-exclusion

7

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 = {x | x A x B}

UA B

8

Difference (example)

{1,2,3} - {2,4} =

{1,3}

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

{x|x Z x is even}

9

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).

= {x | x A}

UA

10

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|x Z x is odd} and U is Z

= {x|x Z x is even}

11

Set identities

A = A

A U = A

A U = U

A =

A A = A

A A = A

( ) = A

A = U

A =

UA

Identity laws

Domination laws

Idempotent laws

Complementation law

Complement laws

12

Set identities

A B = B A

A B = B A

Commutative laws

A (B C) = (A B) C

A (B C) = (A B) C

Associative laws

A (A B) = A

A (A B) = A

Absorption laws

UA B C

13

Set identities (example)

Show A B = A B.

Solution:

A B = {x | x A B }

= {x | ¬(x A B) }

= {x | ¬((x A) (x B)) }

= {x | ¬(x A) ¬(x B) }

= {x | (x A) (x B) }

= {x | (x A) (x B) }

= {x | (x A B)}

= A B

14

Set identities

A B = A B

A B = A B

De Morgan’s laws

There is the similarity between set identities andlogical equivalences.

¬(A B) ¬A ¬B

¬(A B) ¬A ¬B

15

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).

16

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).

17

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 (B C) (A B) (A C)

A (B C) (A B) (A C)

18

Set identities

A (B C) = (A B) (A C)

A (B C) = (A B) (A C)

Distributive laws

000000 0 0

010000 0 1

001000 1 0

111110 1 1

111101 0 0

111101 0 1

111101 1 0

111111 1 1

(A B) (A C)A CA BA (B C)B CA B C

Membership table

19

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)

20

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 (B C)

21

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.

A1 A2 … An = Ai

n

i=1

22

Generalized union (example)

Assume Ai is {i, i+1, i+2, …}. What is Ai?

Solution:

A1 = {1,2,3,…}

A2 = {2,3,4,…}

A3 = {3,4,5,…}

: Ai = {1,2,3,…}

n

i=1

n

i=1

23

Generalized intersection

Assume A1, A2, … and An are sets

The intersection of A1, A2, … and An is theset that contains those elements that aremembers of all sets.

A1 A2 … An = Ai

n

i=1

24

Generalized intersection (example)

Assume Ai is {i, i+1, i+2, …}. What is Ai?

Solution:

A1 = {1,2,3,…}

A2 = {2,3,4,…}

:

An = {n,n+1,n+2,…}

Ai = {n,n+1,n+2,…}

n

i=1

n

i=1

25

Generalized union and intersection

A1 A2 … An … = Ai

A1 A2 … An … = Ai

i=1

i=1

26

Example

Assume Ai = {1,2,3,…,i}. What is Ai and Ai?

Solution:

A1 = {1}

A2 = {1,2}

A3 = {1,2,3}

: Ai = Z+

Ai = {1}

i=1i=1

i=1

i=1

27

Recommended exercises

3,5,7,9,11,13,17,19,24,27,29,45,49